# Image moment

Jump to navigation Jump to search

In image processing, computer vision and related fields, an image moment is a certain particular weighted average (moment) of the image pixels' intensities, or a function of such moments, usually chosen to have some attractive property or interpretation.

Image moments are useful to describe objects after segmentation. Simple properties of the image which are found via image moments include area (or total intensity), its centroid, and information about its orientation.

## Raw moments

For a 2D continuous function f(x,y) the moment (sometimes called "raw moment") of order (p + q) is defined as

${\displaystyle M_{pq}=\int \limits _{-\infty }^{\infty }\int \limits _{-\infty }^{\infty }x^{p}y^{q}f(x,y)\,dx\,dy}$

for p,q = 0,1,2,... Adapting this to scalar (greyscale) image with pixel intensities I(x,y), raw image moments Mij are calculated by

${\displaystyle M_{ij}=\sum _{x}\sum _{y}x^{i}y^{j}I(x,y)\,\!}$

In some cases, this may be calculated by considering the image as a probability density function, i.e., by dividing the above by

${\displaystyle \sum _{x}\sum _{y}I(x,y)\,\!}$

A uniqueness theorem (Hu [1962]) states that if f(x,y) is piecewise continuous and has nonzero values only in a finite part of the xy plane, moments of all orders exist, and the moment sequence (Mpq) is uniquely determined by f(x,y). Conversely, (Mpq) uniquely determines f(x,y). In practice, the image is summarized with functions of a few lower order moments.

### Examples

Simple image properties derived via raw moments include:

## Central moments

Central moments are defined as

${\displaystyle \mu _{pq}=\int \limits _{-\infty }^{\infty }\int \limits _{-\infty }^{\infty }(x-{\bar {x}})^{p}(y-{\bar {y}})^{q}f(x,y)\,dx\,dy}$

If ƒ(xy) is a digital image, then the previous equation becomes

${\displaystyle \mu _{pq}=\sum _{x}\sum _{y}(x-{\bar {x}})^{p}(y-{\bar {y}})^{q}f(x,y)}$

The central moments of order up to 3 are:

${\displaystyle \mu _{00}=M_{00},\,\!}$
${\displaystyle \mu _{01}=0,\,\!}$
${\displaystyle \mu _{10}=0,\,\!}$
${\displaystyle \mu _{11}=M_{11}-{\bar {x}}M_{01}=M_{11}-{\bar {y}}M_{10},}$
${\displaystyle \mu _{20}=M_{20}-{\bar {x}}M_{10},}$
${\displaystyle \mu _{02}=M_{02}-{\bar {y}}M_{01},}$
${\displaystyle \mu _{21}=M_{21}-2{\bar {x}}M_{11}-{\bar {y}}M_{20}+2{\bar {x}}^{2}M_{01},}$
${\displaystyle \mu _{12}=M_{12}-2{\bar {y}}M_{11}-{\bar {x}}M_{02}+2{\bar {y}}^{2}M_{10},}$
${\displaystyle \mu _{30}=M_{30}-3{\bar {x}}M_{20}+2{\bar {x}}^{2}M_{10},}$
${\displaystyle \mu _{03}=M_{03}-3{\bar {y}}M_{02}+2{\bar {y}}^{2}M_{01}.}$

It can be shown that:

${\displaystyle \mu _{pq}=\sum _{m}^{p}\sum _{n}^{q}{p \choose m}{q \choose n}(-{\bar {x}})^{(p-m)}(-{\bar {y}})^{(q-n)}M_{mn}}$

Central moments are translational invariant.

### Examples

Information about image orientation can be derived by first using the second order central moments to construct a covariance matrix.

${\displaystyle \mu '_{20}=\mu _{20}/\mu _{00}=M_{20}/M_{00}-{\bar {x}}^{2}}$
${\displaystyle \mu '_{02}=\mu _{02}/\mu _{00}=M_{02}/M_{00}-{\bar {y}}^{2}}$
${\displaystyle \mu '_{11}=\mu _{11}/\mu _{00}=M_{11}/M_{00}-{\bar {x}}{\bar {y}}}$

The covariance matrix of the image ${\displaystyle I(x,y)}$ is now

${\displaystyle \operatorname {cov} [I(x,y)]={\begin{bmatrix}\mu '_{20}&\mu '_{11}\\\mu '_{11}&\mu '_{02}\end{bmatrix}}}$.

The eigenvectors of this matrix correspond to the major and minor axes of the image intensity, so the orientation can thus be extracted from the angle of the eigenvector associated with the largest eigenvalue. It can be shown that this angle Θ is given by the following formula:

${\displaystyle \Theta ={\frac {1}{2}}\arctan \left({\frac {2\mu '_{11}}{\mu '_{20}-\mu '_{02}}}\right)}$

The above formula holds as long as:

${\displaystyle \mu '_{20}-\mu '_{02}\neq 0}$

The eigenvalues of the covariance matrix can easily be shown to be

${\displaystyle \lambda _{i}={\frac {\mu '_{20}+\mu '_{02}}{2}}\pm {\frac {\sqrt {4{\mu '}_{11}^{2}+({\mu '}_{20}-{\mu '}_{02})^{2}}}{2}},}$

and are proportional to the squared length of the eigenvector axes. The relative difference in magnitude of the eigenvalues are thus an indication of the eccentricity of the image, or how elongated it is. The eccentricity is

${\displaystyle {\sqrt {1-{\frac {\lambda _{2}}{\lambda _{1}}}}}.}$

## Scale invariant moments

Moments ηi j where i + j ≥ 2 can be constructed to be invariant to both translation and changes in scale by dividing the corresponding central moment by the properly scaled (00)th moment, using the following formula.

${\displaystyle \eta _{ij}={\frac {\mu _{ij}}{\mu _{00}^{\left(1+{\frac {i+j}{2}}\right)}}}\,\!}$

## Rotation invariant moments

It is possible to calculate moments which are invariant under translation, changes in scale, and also rotation. Most frequently used are the Hu set of invariant moments:[1][2]

The first one, I1, is analogous to the moment of inertia around the image's centroid, where the pixels' intensities are analogous to physical density. The last one, I7, is skew invariant, which enables it to distinguish mirror images of otherwise identical images.

A general theory on deriving complete and independent sets of rotation invariant moments was proposed by J. Flusser[3] and T. Suk.[4] They showed that the traditional Hu's invariant set is not independent nor complete. I3 is not very useful as it is dependent on the others. In the original Hu's set there is a missing third order independent moment invariant:

${\displaystyle I_{8}=\eta _{11}[(\eta _{30}+\eta _{12})^{2}-(\eta _{03}+\eta _{21})^{2}]-(\eta _{20}-\eta _{02})(\eta _{30}+\eta _{12})(\eta _{03}+\eta _{21})}$