MOMENT2D Function
Computes the 2D moments of an array.
Usage
result = MOMENT2D(image[, p, q])
Input Parameters
image—A 2D or 3D array containing an image; or image, row or pixel-interleaved images.
p—(optional) The p-order of the moment M(pq).
q—(optional) The q-order of the moment M(pq).
Returned Value
result—For 2D image arrays, result is a scalar double containing the computed moment.
For 3D image arrays result is a double array containing the computed moments.
Keywords
CCentroid—If set, computes the column centroid M(0, 1)/M(0, 0).
Central—If set, computes the central moment MC(pq).
CInertia—If set, computes the column inertia MCS(0, 2).
Column—If set, computes the column moment M(0, 1).
Intleave—Scalar string indicating type of interleaving of 3D input image arrays. Valid strings and the corresponding interleaving methods are:
*'pixel'—The input array arrangement is (pxy) for p  pixel-interleaved images of x-by-y.
*'row'—The 3D image array arrangement is (xpy) for p  row-interleaved images of x-by-y.
*'image'—The 3D image array arrangement is (xyp) for p  image-interleaved images of x-by-y.
RCentroid—If set, computes the row centroid M(1, 0)/M(0, 0).
RCInertia—If set, computes the row-column cross inertia MCS(1, 1).
RInertia—If set, computes the row inertia MCS(2, 0).
Row—If set, computes the row moment M(1, 0).
Scaled—If set, computes the central moment MS(pq).
Surface—If set, computes the surface moment M(0, 0).
Discussion
Spatial moments are used in shape analysis. Moments describe the distribution of grayscale values in an image. The equation for a two-dimensional moment is as follows:
The calculation of a central moment, MC, involves the subtraction of the image centroid from each pixel as shown in these equations:
Scaled moments, MS, are divided by p *J q  for moment Mpq computed for an I-by-J image.
Example
; Threshold image for a single blob and compute column centroid.
image = IMAGE_READ(!IP_Data + 'blobs.tif')
thresh_image = THRESHOLD(image('pixels'), 20, 30, /Binary)
moment = MOMENT2D(thresh_image, /CCentroid)
PRINT, moment
See Also