Functions > Image Processing > Feature Extraction > Example: Moment Invariants
Example: Moment Invariants
Use the moment_invariant function for computing the seven invariant spatial moments for an image.
Invariant moments are features of an image that are unchanged under translation, rotation, or scaling of the image, and are very useful in pattern-recognition problems.
For information on using this example, refer to About Image Processing Examples.
Simple Image
1. Define a simple image matrix, and then use the WRITEBMP function to save the image to a file.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(image_matrix.bmp)
2. Calculate the moments up to the second order, or the image center of mass.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
3. Compute the central moments up to the third order.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
4. Compute the normalized moments.
Click to copy this expression
5. Calculate the first moment invariant.
Click to copy this expression
Click to copy this expression
6. Call the moment_invariant function and compare the results.
Click to copy this expression
Click to copy this expression
Geometric Transforms
1. Use the READ_IMAGE function to read in an image.
Click to copy this expression
(flower.bmp)
2. Use the translate, rotate, and zoom functions to perform three types of geometric transforms on the image: translation, rotation, and scaling.
Click to copy this expression
Click to copy this expression
(flower_t.bmp)
Click to copy this expression
Click to copy this expression
(flower_r.bmp)
Click to copy this expression
Click to copy this expression
(flower_z.bmp)
3. Apply moment_invariant to the images and calculate the results.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
The invariant moments are unchanged.
The above results are in reasonable agreement with the invariants computed from the original image. The small errors are due to zero-padding and pixel interpolation that take place in the transformations.
4. Change the transformation values and compare the moment invariants to the original ones.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
The above results are also in reasonable agreement with the invariants computed from the original image.
Was this helpful?