File Exchange

The Seven Invariant Moments

version 1.0 (234 KB) by

Calculates the Seven Invariant Moments in terms of centralized Moments

Updated

Two function files that can be applied on an image to calculate the seven invariant moments defined by Hu(1962)in terms of centralized Moments for purpose of shape recognition . The function to be used directly by the user is
feature_vec(A),where A is a 2D matrix representing an image.
Inside this function another function :cent_moment(p,q,A)is called to calculate the normalized central moments
You can use it in separate.But you don't need to do so when using feature_vec(A)
Attached with the two functions is a pdf file containing short mathematical notes about the theory of Invariant Moments.

sugan raj

Jess

Jess (view profile)

If A is grayscale(uint8), feature_vec return all zero. If A is grayscale(double), feature_vec return some values.
If A is logical, feature_vec return some values as well.

Caution: This file kills my Matlab. It has serious optimisation issues.

andrey

andrey (view profile)

I have the same problem as Try_me34, moments are always zero.
Also the inefficiency of this algorithm makes it practically unusable (I suspect it has a NN or larger order-of-growth).

Jess

Try_me34

Try_me34 (view profile)

Hi, the M always returns zeros ( M1=0 M2=0 .. M7=0).
Am I missing something here?

Henryk Richter

Henryk Richter (view profile)

Thanks for the contribution, the code is quite readable and nicely done.

After tinkering with images, that have been rotated/scaled/translated, I noted some discrepancies between theoretically identical results and your script's output. The following lines in fecture_vec.m need to be corrected to:

M5=(n30-3*n12)*(n30+n12)*[(n30+n12)^2-3*(n21+n03)^2]+(3*n21-n03)*(n21+n03)*[3*(n30+n12)^2-(n21+n03)^2];

M7=(3*n21-n03)*(n30+n12)*[(n30+n12)^2-3*(n21+n03)^2]+(3*n12-n30)*(n03+n21)*[ 3*(n30+n12)^2-(n21+n03)^2 ];

I got the formulas from "Digital Image Processing" by Gonzalez/Woods (and they work just fine) but didn't verify with Hu's paper.

wahyu

very good

Elvis Condori

Elvis Condori (view profile)

Muy buena contribución.

Long

Omid

Omid (view profile)

Lot of redundant calculations. Also instead of using lot of for loops you can try efficient matrix multiplication.

shobhit

shobhit (view profile)

MATLAB Release
MATLAB 7.8 (R2009a)