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.
how to get the result please help me
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.
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).
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.
Muy buena contribución.
Lot of redundant calculations. Also instead of using lot of for loops you can try efficient matrix multiplication.