Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!m45g2000hsb.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Image Invariant Moment
Date: Sat, 14 Jun 2008 18:12:45 -0700 (PDT)
Organization: http://groups.google.com
Lines: 52
Message-ID: <d53f5580-0ac1-4427-8717-695628c4c6b5@m45g2000hsb.googlegroups.com>
References: <g30jp8$d4a$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.67.199
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1213492366 16220 127.0.0.1 (15 Jun 2008 01:12:46 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 15 Jun 2008 01:12:46 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: m45g2000hsb.googlegroups.com; posting-host=75.186.67.199; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
Xref: news.mathworks.com comp.soft-sys.matlab:473831



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