File Exchange

image thumbnail

The Seven Invariant Moments

version 1.0 (234 KB) by

Calculates the Seven Invariant Moments in terms of centralized Moments



View License

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.

Comments and Ratings (15)

sugan raj

how to get the result please help me


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.

Adam Drake

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


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 (view profile)


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

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:


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 (view profile)

very good

Elvis Condori

Muy buena contribución.


Long (view profile)


Omid (view profile)

Ishrat Badami

Ishrat Badami

Ishrat Badami

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

MATLAB Release
MATLAB 7.8 (R2009a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today

Invariant Moments/