Question: I understand that the seven hu invariant moments are for translation, rotation, and scale change of the object, in order to recognize the object independently these factors.

That's why I used the function "moments" from OpenCV to extract the central moments, then I used the function HuMoments to get the seven invariant moments of the following binarized image :

![enter image description here](https://i.stack.imgur.com/ALUHH.jpg)

My first question is regarding the use of the function "moments" from OpenCV. The second parameter is "binaryImage" and I set it true, because it's a binary image, is it ok?

My second doubt is regarding the output of the function "HuMoments": the seven hu invariant moments. I don't understand this data. what data is related to rotation, what for translation and what for scale change?.

Many thanks!, cheers!

Answer: 
**First question :**

It is ok to do so since you have single object in image. If more objects, and want to find moments for each, use contours. Visit : <http://opencvpython.blogspot.in/2012/06/contours-3-extraction.html>

**Second Question :**

(I am too thinking about it after seeing your questions)

HuMoments were brought to light by Mr.Ming Kuei Hu in his paper " [Visual Pattern Recognition by Moment Invariants](http://www.sci.utah.edu/~gerig/CS7960-S2010/handouts/Hu.pdf) " in 1962.

In that paper, he explains them ( with help of high mathematics content, of course). You can check it if you need.

**He states :**

> 
> Theorem: The central moments are invariants under translation.
> 
> 
> 

When you find the moments using moments() function, it returns three types of moments, `spatial moments (Mji), Central Moments (MUji) and Central Normalized Moments ( NUji)`. Check out the docs for [moments()](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments)

At the end of section 4-C, Hu states that, out of seven relations ( [Visit here to see them](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#humoments)), first six are invariant to translation, size and rotation, while `seventh one is skew invariant, which helps to distinguish mirror images.`

I searched a lot about what Hu Moments values means. But all papers says the same dialog : `" Seven Hu Moments are calculated from Central Moments which are invariant to size, position and orientation ".` They don't say what individual values mean.

And the classical book of OpenCV "Learning OpenCV" by Mr.Gary Bradsky has given some insights telling us to explore more. [(Refer page 254)](http://books.google.co.in/books?id=seAgiOfu2EIC&lpg=PA255&ots=hSH1cieHOg&dq=simple%20explanation%20of%20humoments&pg=PA254#v=onepage&q=simple%20explanation%20of%20humoments&f=false)
To answer your second question:

I don't think the invariant moments have any meaning. They're simply guaranteed to be constant for a given shape, no matter how it's shifted, rotated, or scaled.

The kind of meaning you sound like you'd like to know about them:

> 
> what data is related to rotation, what for translation and what for scale change?
> 
> 
> 

doesn't quite make sense since by definition, they are all not related to rotation, translation, and scale. However, once could easily ask a similar question but for other properties, for example:

> 
> what data is related number of corners, roundness, or width to height ratio?
> 
> 
> 

Here I think it's obvious that these moments don't relate to any arbitrary property one would like it to relate to so the answer again is there is no meaning.

So where does that leave us? With this: if we want to compare two objects to tell if their "shape" is similar (and by "shape" we mean that we don't care about rotation, translation, and scale changes), we can calculate the hu invariant moments and compare them. If these values are "approximately" equal, then you can hopefully say that the shapes are "approximately" the same. One would then hope that these moments vary wildly between different shapes - and whether they do or not is an interesting question that maybe someone else can answer.

For example, lets say we calculate some of the the moments (only showing three and with ranges 0 to 1 for simplicity) of a square as:

```
(0.5, 0.5, 0.5)

```

We would then hope that a circle gives something like:

```
(0.5, 1, 0.5)

```

And an oval:

```
(0.5, 1, 0.7)

```

This may allow you to compare these shapes. If you calculate the moments of an unknown shape and get:

```
(0.51, 0.98, 0.47)

```

it's probably (hopefully) a circle.
If however a star gave you:

```
(0.2, 0.6, 0.9)

```

and a crescent also gave the same thing, that wouldn't be so useful. With seven moments though, there's quite a bit of potential for at least a few of the moments to vary significantly for what we may consider important features of a shape.

Hope this helps.