Hi 2 all,
I have one formula for finding moments But i could not know how to proceed further i.e) how to write matlab code for this.Anyone can clarify this? Please send ur suggestion....
imagemoment=summation(imagepixel(i,j)*(x-x')2) / summation(imagepixel(i,j))
summation will be perfformed from 1 to 8
My code:
im=imread('image.jpg'); %binary image of 256x256
u1=xcos(0)+ysin(0);
for i=1:256
for j=1:256
for k=1:8
for l=1:8
sigma(k,l)=im(k,l)*u1; %doubtful statement
end
end
end
end
%here sigma value must be the summation of 64 values that means in x axis 8 values and y axis 8 values(8x8 block) How to perform this cumulative addition Please post how to perform basic summation Thx in advance........
im1=
x=1 to 8
x'=summation(imagepixel*x) / summation(image pixel)
i,j varies from 1 to 8

13 Kommentare

Jan
Jan am 14 Sep. 2011
@Jana: Please post at least a pseudo-code. It is not clear, where the "i,j varies from 1 to 8" should be applied.
harjan
harjan am 15 Sep. 2011
k sir I ll clear that
image moment can be calculated for a 8x8 cell So i,j varies from 1 to 8 and my question is about how to code this formula in matlab please give ur suggestion on that
sig=Σ Im(i,j) *(x-x')pow 2
summation will be from i to j (1 to 8) how to implement summation in matlab please clear that
Jan
Jan am 15 Sep. 2011
@Jana: Please show, what you have done so far and post either Matlab or pseudo-code. It is your turn to make it as clear as possible, what you want to calculate. "Summation will be form i to j (1 to 8)" is simply cryptic. Therefore suggesting any implementations would be wild guessing only. Of course it is possible to guess, what you could need.
Please edit your original question and insert the algorithm in a meaningful notation (ask WikiPedia for "pseudo-code"). Then define the imputs exactly, e.g. "imagepixel" could be a be DOUBLE or UINT8.
harjan
harjan am 17 Sep. 2011
k now i edit the qn sir.......
Jan
Jan am 18 Sep. 2011
@Jana: I'm not a native speaker and parsing your message is very hard for me. I'd appreciate, if you try to use proper English. Thanks.
Image Analyst
Image Analyst am 18 Sep. 2011
Even for a native English speaker like me it appears as gibberish, and takes twice as long to figure out what she means than if she had just written in standard English.
harjan
harjan am 19 Sep. 2011
k Let i explain my qn clearly
How to perform summation(sigma) operation for a certain value
(cumulative summation like c sum=sum+consecutive terms)
I have little bit confusion that how to code summation in matlab....Sorry for the inconvenience.......
Jan
Jan am 19 Sep. 2011
@Jana: "Sorry for the inconvenience" on one hand, but a repetition of "k Let i explain my qn clearly " on the other. This is not funny, nor fancy nor efficient - this is simply hard to read. Obviously you are not interested in my assistence. Perhaps there are enough others who like this slang. Good luck.
@Image Analyst: I'm not using standard English also, but I really try to get as near as I can.
harjan
harjan am 19 Sep. 2011
Oh Dont mistake me...I need ur guidance but somewhat its difficult to explain my qn......
Image Analyst
Image Analyst am 19 Sep. 2011
Then don't use words not in the dictionary such as ur, qn, ll, k, thx, etc. In other words, you're using a computer with a real keyboard, not a cell phone, so use the keyboard. That's what it's there for.
How many moments do you need? Is there any reason why you're not using mean(), std(), and var()? Do you need moments higher than 2? If so, why? I've rarely, if ever, found that I needed some higher moment to do anything meaningful.
harjan
harjan am 20 Sep. 2011
If you consider an image of size 256x256 then i have to find out 32 moments in x and y coordinates(256x256/8=32x32)that means divide the image into 8x8 blocks and findout single moment for a particular block Hence it should have 32x32 moments...Please give Your idea.........
Jan
Jan am 20 Sep. 2011
Please write a comment to proecsm's answer. Does it solve your problem? If not, why? What modifications are needed?
harjan
harjan am 20 Sep. 2011
Yes I got some idea about how to perform summation.But still i need some clarification regarding that....
If i use mean() or var() to findout mean and sigma values then how to proceed it?
First divide the image using mat2cell
Then Apply the mean and var for each matrix
But How to code this
I have the sample code that is,
a=8;
b=8; %window size
x=size(image,1)/a;
y=size(image,2)/b;
m=a*ones(1,x); n=b*ones(1,y);
I=mat2cell(image,m,n);
sigma=var();%how to code this
Please post ur ideas.....

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

bym
bym am 18 Sep. 2011

0 Stimmen

for each 8x8 block, you will want to calculate:
im = rand(8)>.5; % generate image data
xbar = 4.5; % mean x
ybar = xbar; % mean y
im2moment = zeros(8); % allocate memory
for c = 1:8
for r = 1:8
im2moment(r,c) = (r-ybar).^2*(c-xbar).^2*im(r,c);
end
end
imagemoment = sum(sum(im2moment))/sum(sum(im));

8 Kommentare

harjan
harjan am 20 Sep. 2011
Yes I got some idea about how to perform summation.But still i need some clarification regarding that....
If i use mean() or var() to findout mean and sigma values then how to proceed it?
First divide the image using mat2cell
Then Apply the mean and var for each matrix
But How to code this
I have the sample code that is,
a=8;
b=8; %window size
x=size(image,1)/a;
y=size(image,2)/b;
m=a*ones(1,x); n=b*ones(1,y);
I=mat2cell(image,m,n);
sigma=var();%how to code this
Please post ur ideas.....
Jan
Jan am 20 Sep. 2011
@Jana: You almost got it, there is only one "ur" in this comment. In standard English this term is written "your" and it would be kind to use this consequently.
You need two FOR loops to run through the columns and rows of your cell "I".
harjan
harjan am 21 Sep. 2011
oh my god sorry for my mistake I will try with your idea and if any doubt I will post here......Thank You so much for your assistance
harjan
harjan am 22 Sep. 2011
Please explain how to get im2moment.........
bym
bym am 22 Sep. 2011
@jana: So, there is an assignment in my code that creates a 8x8 matrix of zeros:
im2moment = zeros(8)
this is to allocate the memory to store the variable. The statement
im2moment(r,c) = (r-ybar).^2*(c-xbar).^2*im(r,c);
fills up the matrix with values for the second moment
Image Analyst
Image Analyst am 23 Sep. 2011
Technically this is the second central moment. Get rid of the xbar, ybar if you want the raw moments, which is unlikely. Replace the 2 by the order if you want higher order moments. For more info, see http://en.wikipedia.org/wiki/Image_moments
harjan
harjan am 23 Sep. 2011
Thanks a lot sir.........
harjan
harjan am 30 Sep. 2011
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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

heba ahmed
heba ahmed am 23 Feb. 2020

0 Stimmen

b=uint8(zeros(256,256));
>> [i j]=size(b);
>> for i=1:256 for j=1:256 b(i,j)=i;
end
end
>> imshow(b,[8]);

Gefragt:

am 14 Sep. 2011

Beantwortet:

am 23 Feb. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by