next up previous contents
Next: Zernike moments and the Up: Measurement practice Previous: Scanline intersections and weights

Moments

Suppose we have isolated a character as a set of pixels. Let us not draw a box around it, let us first find its centre of gravity. If A is the set of pixels in the figure, with integer co-ordinates x and y for each pixel p in A, then let fA be the characteristic function of A, i.e. % latex2html id marker 1506
$f_A \left(\begin{array}
{c} x \\  y \end{array} \right) = 1$ iff there is a pixel of A at location % latex2html id marker 1508
$ \left(\begin{array}
{c} 
 x \\  y \end{array} \right) $,and otherwise fA takes the value 0. Then we can write the count of the number of pixels in A as

\begin{displaymath}
% latex2html id marker 1382
\sum f_A \left(\begin{array}
{c} x \\  y \end{array} 
\right) \end{displaymath}

where the summation is taken over the whole plane of integer value pixel locations. We can write the mean of the x values of all the pixels in A in the form:

\begin{displaymath}
% latex2html id marker 1383
\bar{x} = \frac{ \sum x f_A \lef...
 ...\sum f_A \left(\begin{array}
{c} x \\  y \end{array} 
\right)} \end{displaymath}

and similarly

\begin{displaymath}
% latex2html id marker 1384
\bar{y} = \frac{ \sum y f_A \lef...
 ...\sum f_A \left(\begin{array}
{c} x \\  y \end{array} 
\right)} \end{displaymath}

where sums are taken over the whole plane. (Since fA is zero over all but a bounded region, we don't really have to do as much arithmetic as this suggests.)

These numbers give us information about the set A. We can rewrite things slightly by defining the (p,q)th moment of fA (or of A) by

\begin{displaymath}
% latex2html id marker 1385
\mu_{[p,q]} = \sum x^p y^q f_A \left(\begin{array}
{c} 
 x \\  y \end{array} \right) \end{displaymath}

for any natural numbers p,q,

and the normalised (p,q)th moment of fA (or of A) by

\begin{displaymath}
% latex2html id marker 1386
\mu_{[p,q]} = \frac{\sum x^p y^q...
 ...{\sum
f_A\left(\begin{array}
{c} x \\  y \end{array} 
\right)} \end{displaymath}

for any natural numbers p,q,

Then the moment $\mu_{[0,0]}$ is the pixel count of A,the mean x-value of A is the moment $ \mu_{[1,0]}$ divided by the pixel count,or alternatively the normalised (1,0) moment, and the mean of the y-values of the pixels of A is the moment $\mu_{[0,1]}$ divided by the pixel count.

It is easy also to compute higher order moments. These give extra information about the distribution of the pixels in A.

The central moments are computed in the same way, except that the origin is shifted to the centroid % latex2html id marker 1528
$ \left(\begin{array}
{c} \bar{x} 
 \\  \bar{y} \end{array} \right)$ for all the pixels of A.

All the moments $\mu_{[p,q]}$ where p+q takes the value v, are called moments of order v. A little thought and recollection of statistics will no doubt remind you that the second order central moments, moments of order 2, i.e. the (2,0), (0,2) and (1,1) central moments, are the elements of the covariance matrix of the set of points, except for a scaling dependent on the number of points. The use of central moments is clearly a way of taking out any information about where the set A actually is. Since this is a good idea, we have a distinct preference for the central moments. The three central moments of order 2 would allow us to distinguish between a disk and a thin bar rather easily. In the exercises we ask you to compute the central moments for some simple shapes.

Example We give an example for the easy case of sets A and B defined by

\begin{displaymath}
% latex2html id marker 1387
A = \{\left(\begin{array}
{c} x ...
 ...{\fam11\tenbbb Z}^2 : -5 \leq x \leq 5\ \&
-1 \leq y \leq 1 \} \end{displaymath}

and

\begin{displaymath}
% latex2html id marker 1388
B = \{\left(\begin{array}
{c} x ...
 ...\fam11\tenbbb Z}^2 : -3 \leq x \leq 3 \ \&
-2 \leq y \leq 2 \} \end{displaymath}

Then A has 33 pixels and B has 35; B is squarer than A. Both have the origin as the centroid so as to save us some arithmetic.

A has three rows, so to calculate $\mu_{[2,0]}(A)$ which is the sum of the squares of all the x-values of the pixels in A we get

\begin{displaymath}
3(-5)^2 + 3(-4)^2 + 3(-3)^2 + 3(-2)^2 + 3(-1)^2 
 + \cdots + 3(5)^2 \end{displaymath}

i.e.$\mu_{[2,0]}(A)= 330 $. Similarly, $\mu_{[0,2]}(A) 
= 26$, and

\begin{displaymath}
\mu_{[1,1]}(A) = (-5)(-1) + (-4)(-1) + \cdots+ 
(4)(-1)+ (5)(-1) \end{displaymath}

\begin{displaymath}
+ (-5)(0)+\cdots+(5)(0) + (-5)(1)+ \cdots+ 
(5)(1) = 0 \end{displaymath}

So the three second order moments, in the right order, give the vector % latex2html id marker 1538
$\left(\begin{array}
{c}
330 \\  0 \\  26 \end{array} \right)$, while the same calculation for B gives % latex2html id marker 1540
$\left(\begin{array}
{c} 
140 \\  0 \\  70 \end{array} \right)$.

So if we were to represent these objects as points in ${\fam11\tenbbb R}^3$, it would be easy to tell them apart. Unfortunately, it takes rather higher dimensions, i.e. higher order moments, to discriminate between characters, but it can be done by the same methods.


next up previous contents
Next: Zernike moments and the Up: Measurement practice Previous: Scanline intersections and weights
Mike Alder
9/19/1997