Image analysis

Hello Sir,
I have one doubt regarding for loop.I have 256x256 image then after some operations performed, it would produce 32x32 size output(that means by analysing 8x8 values it will show a singular value 1) How it could be done?Can i try it with mat2cell? But i need some information about mat2cell in depth Please post your suggetions.
My sample code
im=imread('flower.png') %256x256 image
for x=1:8
for y=1:8
im1(x,y)=im(x,y)*cos(0)+im(x,y)*sin(0);
end
end
My question is how to iterate this loop upto 256 values?

8 Comments

Image Analyst
Image Analyst on 1 Oct 2011
Since cos(0) = 1 and sin(0) = 0, you'll simply get im1 = im with this code. And im1 will be the same size. That is not really "analysing." Tell me what you really want to accomplish. Do you want to subsample, blur, sharpen, what? Is im a color image or a grayscale image?
harjan
harjan on 3 Oct 2011
Hello Sir,
It is a grayscale image.Yes it is related to subsampling that means consider the image as 8x8 block, analyse it and conclude it as a single value.
im=imread('flower.png') %256x256 image
for x=1:8
for y=1:8
im1(x,y)=im(x,y)*cos(0)+im(x,y)*sin(0);
im2=sum(sum(im1)); %have some intermediate lines
end
end
But i need to know that how to iterate this 8,8 for loop upto the entire image of size 256?
By my code(above to this),I will get a single value by processing the 64 values(8x8)And i have a problem that how to iterate this for loop to next (8x8 )block....Sorry for the disturbance....I need your guidance....Please post your answers....
Image Analyst
Image Analyst on 3 Oct 2011
You can use blockproc() or a set of 4 nested for loops (for the slow, manual way of doing it), but what on earth are the sin() and cos() for??? And you still haven't said what you want to do. What EXACTLY does "process" mean? Does it mean average, median, standard deviation, range, max, min, what????? Because your loop simply doesn't do ANYTHING other than assign im to im1.
The sin() and cos() probably have the side-effect of changing the data type.
harjan
harjan on 4 Oct 2011
I have to find image moments for each and every 8x8 cell.....(first order moment)if i use blockproc() how to do this? Thanks a lot for your response.......
First code a routine that finds the first-order moment of a single 8x8 array. Now wrap it in an anonymous routine that extracts the data array from the information passed by blockproc to routines called by it. Now pass that anonymous routine to blockproc .
You appear to already have a solid foundation for the code to find the moments for a single 8x8 block, in your previous question http://www.mathworks.com/matlabcentral/answers/15798-image-processing
harjan
harjan on 7 Oct 2011
Ok sir, I apply your idea to my project and how to pass the 256x256 to that function?
My coding:
image=imread('D:\Jana\images\jann.jpg') %256x256 image
s=moment(image);
function s = moment(image)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
ima=double(image);
for i=1:8
for j=1:8
ui(i,j)=i*cos(90)+j*sin(90);
uib(i,j)=ui(i,j)*ima(i,j);
end
end
end
please help to modify this sir......

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 3 Oct 2011
newim = blkproc(im, [8 8], @(b) sum(double(b(:))) );

2 Comments

harjan
harjan on 3 Oct 2011
Can you please explain this formula Sir,
i know somewhat about blkproc but still i dont know what is @b indicates......
Read the documentation for "function" to see what @(b) indicates.

Sign in to comment.

Walter Roberson
Walter Roberson on 7 Oct 2011
image=imread('D:\Jana\images\jann.jpg') %256x256 image
s = blkproc(image, [8 8], @moment);
Warning: your code with cos(90) and sin(90) is very very unlikely to work. Your current version is worse that way than when we asked you before why you had the cos() and sin() in the equations, which is a question I do not recall that you ever answered.

2 Comments

Image Analyst
Image Analyst on 7 Oct 2011
And it appears jana does not yet know that there is a cosd() and sind() which should be used when inputting values in degrees instead of radians. (Not that they should even be in there in the first place!)
harjan
harjan on 8 Oct 2011
Oh sorry sir I know about sind and cosd.By mistake i forget to put sind instead of sin.Now my problem is to find the moment along x axis and y axis for that purpose i include sin and cosine terms into my code(to find in which axis the moment is maximum.Thus we can identify the orientation)So how to code this.....Provide your guidance...Thanks in advance..

Sign in to comment.

Asked:

on 1 Oct 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!