# Digital image moments in plain English

I'm studying OpenCV and, in computer vision and image processing, people speak of blobs, contours, connected regions, and I sometimes hear the phrase "image moments".

I know of an article on Wikipedia about it, but I think it is too technical. I don't really want to go deep into the math background but I want to know what I'm talking about.

Could someone explain to me what image moments are in plain English?

-

## 2 Answers

Image moments are the same notion as in Mechanics. The first order moment will give you the center of mass, where the mass of a pixel is its intensity, second order moment will tell you how this mass varies around the center of mass, etc. In the same way as you obtain a frame of inertia for a real world object, you can obtain one from the image moments. That will give you the principal axes of the shape you want to describe.

-
Are you sure the last phrase, "that will give you the principal axes of the SHAPE you want to describe" is correct? I think first, second, etc. moments don't relate to orthogonal axes, or orientation in general, but to the overall statistic characteristic of the image, isn't it? (not really sure, actually) – heltonbiker Jan 8 '13 at 1:14
Yes, I'm pretty sure. In a standard context, you will compute the moments on a binarized image where background = 0 and object = 1. Then, the first order moment of this gives you the center of mass, and the matrix of the 2 second order gives you the 2 principal axis after diagonalization. It's a way to normalize shapes btw. Think of mechanical inertia: it's dirtily related to how an object is balanced and around which point it will rotate. – sansuiso Jan 8 '13 at 20:30
What confuses me most is this part form a previous answer: "In image processing, if you want to compare images, you might not want the comparison to be sensitive to minor things like rotation, translation, and scale (since the image remains fundamentally the same)." Since principal axes are sensitive to orientation (rotation), then after all the second moment IS or IS NOT sensitive to rotation? – heltonbiker Jan 8 '13 at 21:19
What you do is to express the shape in the frame defined by the principal axes. This performs an implicit rotation, that will in particular make horizontal the first principal axis. So the second moment, expressed in this new frame, becomes invariant to rotation. – sansuiso Jan 8 '13 at 22:30
sorry but, how many moments can be calculated? – nkint Jan 12 '13 at 16:56

An image moment is simply a number that characterizes the image, construed as the realization of a spatial random variable. If you've taken any probability class, you should remember the concepts of mean and variance, which are derived from the first and second moments of the random variable (the n'th moment of an r.v. is the expectation of its n'th power). Furthermore, the moments of a random variable collectively prescribe its distribution. In other words, you can reduce a probability distribution to a sequence of numbers, and this is useful when you want to compare distributions numerically.

In image processing, if you want to compare images, you might not want the comparison to be sensitive to minor things like rotation, translation, and scale (since the image remains fundamentally the same). Thus the motivation behind invariant moments you see in the Wikipedia article you cited.

-