# Contour and area, raw (spatial) and central image moments

I recently started using image moments for image processing of binary images. I read that the $0^{th}$ order contour moment is the perimeter and the $0^{th}$ order area moment is the area. These raw moments are both given by:

$M_{ij} = \sum_{x}\sum_{y}x^iy^j$.

This means If I have an image like this (but binary, foreground pixels shown in blue), the $0^{th}$ moment will correspond to the the perimeter, since it's an image of a contour : On the other hand, if I have an image like this (foreground shown as while), I will get the area of the object as the $0^{th}$ moment: Since I want to use the contours to get more properties, I also calculate the higher order ($1^{st}$, $2^{nd}$, $3^{rd}$ order) raw contour moment. I want to use these to get the central moments.

Formulas I am using to get the central moments are:

$\mu_{00} = M_{00}$

$\mu_{01} = 0$

$\mu_{10} = 0$

$\mu_{11} = \frac{M_{11}}{M_{00}} - x_c*y_c = \frac{M_{11}}{M_{00}} - (\frac{M_{10}}{M_{00}})*(\frac{M_{01}}{M_{00}})$

The formulas for calculating central moments are using raw moments. My question is: Which raw moments are used to calculate central moments, area or contour?. My guess is area moments, since the $0^{th}$ order central moment is also equal to the area, which is in fact the $0^{th}$ order area moment.

Additionally, can I calculate the central moments based on contour raw moments?

• Oct 31, 2012 at 9:40
• Yes the difference between area moments and contour moments is clarified there. Now only more info on central moments and the relation between them would be nice :). Oct 31, 2012 at 9:43
• Central moments of contour, or area? Nov 5, 2012 at 12:40
• Central moments of contour need to be clarified. I'd like to know how to get the central moments based on the contour moments. Because if I calculate a central moment based on the contour and also one based on the area, I see that they are not the same. Therefore I can't calculate the orientation or eccentricity of the figure correctly. (en.wikipedia.org/wiki/Image_moment) Nov 5, 2012 at 19:50
• You say in your first sentanse: "I read that the 0th order contour moment is the perimeter and the 0th order area moment is the area." Can you please provide the source for that? (I was killing myself to find something more concrete on contour moments) Apr 5, 2013 at 14:30

Actually, I was surprised how hard was it do deduct a proper definition of contour versus "normal", non-contour moments of an image. After reading a bunch of materials, here come my conclusions.

Firstly, in order to understand moments, and especially the difference and the usage of spatial (what the OP calls "raw"), central, and central normalized moments, I found two very good materials:

• Excellent manual with simple mathematics. Don't be scared by the integrals - you can read all of them as summations.

Also, it has a small overview on OpenCV functions used to operate with this moments. It's very old material (2001), so the OpenCV manual it is referring to is a bit old, but it still helps.

And than there's the wonderful third chapter, specifying which moment is used to describe which characteristic of a moment.

• (image processing blog) Utkarsh: Image Moments

Simple, short and friendly. I found a lot of good material on this blog before.

Disclaimer AI Shack seemed to be offline at some point. Here is the homepage from the AI Shack author, where he talks about this project, so it still seems to be supported. I hope it comes back online soon, but if not maybe it can be tracked through the author's webpage.

Shortly, the spatial moments give information about the object in the image, i.e. related (dependent) on the object position.

The central moments are adjusted for translational invariance, by moving the origin of the "coordinate system" used for calculations to the centroid (center of gravity) of the object in question.

Finally, the central normalized moments are scaled by the area of the object, and are thus scale invariant in addition to translational invariance.

Now for the actual question part: what about contour moments?

The deductions from this part are mostly based on

And the most important quotes from those sources:

The moments of a contour are deﬁned in the same way but computed using the Green’s formula.

(OpenCV reference manual)

In plane geometry, and in particular, area surveying, Green's theorem can be used to determine the area and centroid of plane figures solely by integrating over the perimeter.

(wiki for Green)

Moreover, cvContourMoments is now just an alias for cvMoments.

Based on that, I would deduce that contour moments does not refer to special measures of the object contours, but instead to a particular way to calculate image moments, only using the contour information (instead of pixel information for the whole image).

The difference, in the fundamental case, would be how both are calculated.

• My guess would be that the direct implementation would work by pixel-by-pixel summation, directly implementing the formula. The object is expected to be filled.
• My guess for the contour moments would be that the image contours are first determined (consult OpenCV manual) and then the Green theorem is applied on the contour data.

That would make the measurements slightly different for real images because the methods would differ in their: sensitivity to: noise, scaling, discretisation (pixel grid instead of continuous image). Also, the speed: calculating using contours is faster than using the direct approach. I would speculate that they would give perfectly equal results for an (idealized) continuous black and white image with no noise.

So, to answer your questions: the moments should be the same (differing because of noise etc). You can use spatial (raw) moments calculated by both methods to determine central moments (that will still describe the same thing).

Further support of this claims is the existence of this article (I only read the abstract, but should be very relevant, and even the abstract is informative) from 1994:

Note about getting the perimeter measure: I think, to get the "perimeter" which is actually just area of the contour, I would calculate the $0^{th}$ moment of the image of the contours of the objects, but treat the contours as a really thin object, instead of as "contours of an object".

All further measurements would of course differ if you used this moment further.

• some links are broken Jan 28, 2014 at 8:23
• @nkint I fixed the first broken link... the name of the author and the manuscript were enough to find it as a first hit on Google, which is why I included them in the first place. I'd appreciate anybody editing in the correct info if they notice a link is broken again, and if it's fixable by simple Google search as this was. The second link, AI Shack seems to be temporarily offline... I added a link to the authors homepage, and a little disclaimer describing the the situation. I hope it helps. Jan 29, 2014 at 20:17

No matter of contour or area moments, central moments mean moments that are computed in a centered reference frame, i.e., a frame centered on the mean of your phenomenon.

In your case, this means that you need to compute the first order moments $(\mu_{0,1},\mu_{1,0})$ (contour or area), then compute subsequent moments using $\mathbf{\mu} = (\mu_{01},\mu_{10})$ as origin. This is a simple translation (subtraction of coordinates).

Also related, this question about vocabulary.