Thread Subject: Image Invariant Moment

Subject: Image Invariant Moment

From: Nan W.

Date: 14 Jun, 2008 14:15:04

Message: 1 of 5

Dear all,

I tried to implement the image invariant moment but it
seems like it doesn't work well. Would you please check
the code for me? The goal is just to find the second
moment of the image though but since it doesn't work I
also try the 3rd and 4th and still doesn't work out.

Noted thanks for the guideline code from Yuan-Liang Tang.



function [m2 m3 m4]=findmoment(im)

%im=im/max(max(im));
cx = immoment(im, 1, 0);
cy = immoment(im, 0, 1);


u20= immoment(im,2,0,cx,cy);
u02= immoment(im,0,2,cx,cy);
u11= immoment(im,1,1,cx,cy);

u30= immoment(im,3,0,cx,cy);
u03= immoment(im,0,3,cx,cy);
u12= immoment(im,1,2,cx,cy);
u21= immoment(im,2,1,cx,cy);


m2=sqrt((u20-u02).^2+4*u11.^2);

m3=(u30-3*u12).^2 + (3*u21-u03).^2;

m4=(u30+u12).^2 + (u21+u02).^2;

function m = immoment(im, p, q, cx, cy)
% Compute image moment
[y x v] = find(im);
if nargin == 5
  x = x - cx;
  y = y - cy;
  m = sum(x.^p .* y.^q .* v)/sum(v).^((p+q)/2+1);
end
    m = sum(x.^p .* y.^q .* v)/sum(v);
return



**** Thank you ****

Subject: Image Invariant Moment

From: Nan W.

Date: 14 Jun, 2008 14:18:01

Message: 2 of 5


>
> m2=sqrt((u20-u02).^2+4*u11.^2);
>

is actually

> m2=((u20-u02).^2+4*u11.^2);

sorry I was trying various of versions though.

Please help I really stucked!
Thank you so much

Subject: Image Invariant Moment

From: ImageAnalyst

Date: 14 Jun, 2008 14:29:14

Message: 3 of 5

On Jun 14, 10:18=A0am, "Nan W." <iiuu_c...@yahoo.co.jp> wrote:
> > m2=3Dsqrt((u20-u02).^2+4*u11.^2);
>
> is actually
>
> > m2=3D((u20-u02).^2+4*u11.^2);
>
> sorry I was trying various of versions though.
>
> Please help I really stucked!
> Thank you so much

------------------------------------
NaN:
Is your original image a uint8 (with values of 0-255)? If so the
squaring and summing operations may exceed its range and it will
either clip or wrap around (I don't know which), or maybe just give an
error or warning or NaN (I'm not sure). You might need to convert
your image to floating point with single() or double() before
computing the moments.

You need to detail more what "doesn't work out" actually means. Does
that mean there is an error message, warnings displayed in the command
window, or the results just don't seem like the correct results?
Regards,
ImageAnalyst

Subject: Image Invariant Moment

From: Nan W.

Date: 14 Jun, 2008 23:19:02

Message: 4 of 5

I'm sorry for haven't posted the details.

My test image is in gray-scale and the thing that is
incorrect is the result (value) of the output 'm2 m3 m4'.

I set up the experiment as
1.Reference image
2.Translated and Rotated image

Then I cropped a part from Image1 and almost exactly portion
from Image2 with a circular mask to make it safe for some
unwanted details. Then only pixel in those masks are fed
into my above moment invariant code. But the result didn't
give the nearly the same moment value from both. Some are!
but some aren't! So I was wondering whether my code is wrong
or not.

Please guide me so. Thank you so much.

Subject: Image Invariant Moment

From: ImageAnalyst

Date: 15 Jun, 2008 01:12:45

Message: 5 of 5

On Jun 14, 10:15=A0am, "Nan W." <iiuu_c...@yahoo.co.jp> wrote:
> Dear all,
>
> I tried to implement the image invariant moment but it
> seems like it doesn't work well. Would you please check
> the code for me? The goal is just to find the second
> moment of the image though but since it doesn't work I
> also try the 3rd and 4th and still doesn't work out.
>
> Noted thanks for the guideline code from Yuan-Liang Tang.
>
> function [m2 m3 m4]=3Dfindmoment(im)
>
> %im=3Dim/max(max(im));
> cx =3D immoment(im, 1, 0);
> cy =3D immoment(im, 0, 1);
>
> u20=3D immoment(im,2,0,cx,cy);
> u02=3D immoment(im,0,2,cx,cy);
> u11=3D immoment(im,1,1,cx,cy);
>
> u30=3D immoment(im,3,0,cx,cy);
> u03=3D immoment(im,0,3,cx,cy);
> u12=3D immoment(im,1,2,cx,cy);
> u21=3D immoment(im,2,1,cx,cy);
>
> m2=3Dsqrt((u20-u02).^2+4*u11.^2);
>
> m3=3D(u30-3*u12).^2 + (3*u21-u03).^2;
>
> m4=3D(u30+u12).^2 + (u21+u02).^2;
>
> function m =3D immoment(im, p, q, cx, cy)
> % Compute image moment
> [y x v] =3D find(im);
> if nargin =3D=3D 5
> =A0 x =3D x - cx;
> =A0 y =3D y - cy;
> =A0 m =3D sum(x.^p .* y.^q .* v)/sum(v).^((p+q)/2+1);
> end
> =A0 =A0 m =3D sum(x.^p .* y.^q .* v)/sum(v);
> return
>
> **** Thank you ****

---------------------------------------
Well you're passing in 5 arguments so you're getting into the if
statement and assigning m, yet right after that if statement, you're
setting m to some other value, so, in essence, the if statement was
useless. Is that what you want to do?
Regards,
ImageAnalyst

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com