|
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
|