Wednesday, August 26, 2015

The invariance of moments in Virtual 2D space

Image Moments

A moment is an abstract concept used as a quantitative measure of a set of points. In physics, if the points represent mass, the zeroth moment refer to the total mass. Higher moments are also used to derive other important measurements, such as  the center of mass (first moment divided by the total mass) and rotational inertia (second moment).

Under certain conditions these moments are invariant to changes in coordinates, scaling, and orientation. In the case of the center of mass, moving all the points to a new location, will not change its value, provided their relative locations (with respect to the origin) are maintained. Another example: in geometry, a circle (on the x-y Cartesian plane) will not increase or decrease in size, provided the relation (x-xo)2 + (y-yo)2 = R2 is maintained. (xo,yo) refers to the new origin.

A similar set of quantities are used can be used to analyze shapes and images.

For a gray scale image I(x,y), its moments are defined as


Each point in the image is weighted using it's gray level value I(x,y), coordinates (x,y) and  i, j. M00 is analogous to the total mass of the image. For a binary images consisting only of 0 and 1 values, it is analogous to the area. Notice that the black background I(x,y) = 0 does not contribute to Mij.

In its current form, this is not invariant to changes in location. In this case, we can derive central moments using M00.


with
 


Finally, for changes in scale, these are the scale-invariant moments



for i + j >= 2

Hu derived a set of invariant moments that can be used in visual pattern recognition

where I1 is analogous to the moment of inertia. I7 is the skew operator can be used to identify mirror images. The full set provides a handy way of determining whether any two images are identical or just mirrored versions of one another. Because it is invariant due to rotation, no further transformations are needed to facilitate the identification process. One can simply take a snapshot of the region of interest, subtract the background, and compute the corresponding image moments and compare it to known measurements. This also bodes well for software automation. Finally, due to scale invariance, theoretically, all distinct properties of the image can be observed regardless of the size of the sample. A practical application of this is when you maintain an image database, you need not store multiple versions of the image taken at different magnifications and/or camera zoom levels.

We performed numerical experiments on three types of images: grey scale image, synthetic image, and an edge image of a real object.

Grayscale image


original
flipped
scale (x 2.0)
rotated (90 degrees)

translated

Invariant Moments


originalflippedscaled (x 2.0)rotated (90o)translated
I19.8953059.8953059.8953859.8953059.895305
I2 1.4017961.4017961.4017961.4017961.401796
I31.2125521.2125521.2125521.2125521.212552
I4 3.6863993.6863993.6863993.6863993.686399
I52.4042422.4042422.4042422.4042422.404242
I6 4.3517434.3517434.3517434.3517434.351743
I7 -5.4228675.422867-5.422867-5.422867-5.422867

In all of the moments, are all invariant under translation, scaling and rotation. For the flipped image (horizontal), the changing sign of the I7 indicates the flipped image. Under scaling and translation, there is no significant change in the values.

Synthetic binary edge image

original
flipped
scale (x 2.0)
rotated (90 degrees)
translated (to 52,52)

Invariant moments


original flipped vertically scaled (x 2.0) rotated (90o) translated
I1  6.353301 6.353353 6.353817 6.353301 6.353301
I2 4.345424 4.347722 4.345424 4.345424 4.345424
I3  2.405847 2.400483 2.405847 2.405847 2.405847
I4 8.438474 8.431695 8.438474 8.438474 8.438474
I5  1.202347 1.199559 1.2023471.202347 1.202347
I6  5.562628 5.559628 5.562628 5.562628 5.562628
I7   -5.926998E-21 5.402808E-7 -1.327250E-20 0.000000 -3.806771E-21

For the synthetic case, only the skew operator shows much variance and I4 for the flipped image. A work by Flusser and Suk demonstrated that some of the image moments by Hu are not completely independent. They have derived a new set. We have tested this synthetic image against Flusser's set as show below


Flusser-Suk rotationally  invariant moments


originalflippedscaled (x 2.0)rotated (90o)translated
I1 6.3534256.3534776.3539426.3534256.356209
I2 24.361843 24.5129224.35824624.361843238.111670
I3  -160.562535-161.6012-160.538824-160.562535868.962119
I4 0.0000000.037867040.0000000.000000-1304.758197
I5 -1781.199425-1796.049-1780.804879-1781.199425-46188.231920
I6 0.0000000.91207940.0000000.000000-11545.862316

To some degree, the rotated image is nearly identical to the original in Flusser's moments. At this moment, I observe the large deviations on the translated and flipped versions. Could it be that Flusser's moments are not translation invariant? Need to verify this.

Edge image (chromosome)

original
flipped
scale (x 2.0)
rotated ( -90 degrees)
translated

Invariant moments


original
flipped
scaled (x 2.0)
rotated (-90o)
translated
I1
3.15595718
3.15595718
3.15699884 3.155957183.15595718
I2 
5.07844102
5.078441025.078441025.078441025.07844102 
I3
0.79003543
0.79003543 0.790035430.790035430.79003543
I4
0.25408407
0.254084070.25408407  0.254084070.25408407 
I5
0.11280773
0.11280773 
0.11280773
0.11280773
0.11280773
I6
0.35999914
0.359999140.359999140.359999140.35999914
I7  
-0.015285180.01528518-0.01528518-0.01528518-0.01528518

For the edge image of the chromosome from the previous exercise, all values are identical except for the skew operator of the flipped case.


Some thoughts

This has been a challenge to implement. A lot of code-rewrites were done especially on the functions computing for the complex moments.

We've used images in this exercise, but in theory it should also be applicable for shapes or data containing only the vertices of polygons. Operating on shapes meant that rotation operations would not totally result in aliasing or loss of information. One need only guard against number precision (before and after the floating point operations), truncation and other related issues. Overall M00 should remain constant.

I've started coding these at: https://github.com/daelsepara/pixelprocessing/tree/master/Shape


References

  • Hu, M.K. (1962) "Visual Pattern Recognition by Moment Invariants", IRE Trans. Info. Theory, vol. IT-8, pp.179–187, 1962
  • Flusser, J   "On the Independence of Rotation Moment Invariants", Pattern Recognition, vol. 33, pp. 1405–1410, 2000
  • Soriano, M (2015), Moment Invariants, lecture notes presented in Physics 301 - Special Topics in Experimental Physics (Advanced Signal and Image Processing) at National Institute of Physics, University of Philippines Diliman, Quezon City on 11 August 2015

No comments:

Post a Comment