Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Image Invariant Moment
Date: Sat, 14 Jun 2008 14:15:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 50
Message-ID: <g30jp8$d4a$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1213452904 13450 172.30.248.38 (14 Jun 2008 14:15:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 14 Jun 2008 14:15:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1410327
Xref: news.mathworks.com comp.soft-sys.matlab:473775



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