moments {EBImage} | R Documentation |
Computes moments and invariant moments from image objects.
moments(x, ref) cmoments(x, ref) rmoments(x, ref) smoments(x, ref, pw=3, what="scale")
x |
An Image object or an array containing object masks.
Object masks are sets of pixels with the same unique integer value. |
ref |
An Image object or an array, containing the
intensity values of the objects. |
pw |
A numeric value specifying the maximum moment order to compute. Default is 3. |
what |
A character string partially matching central or
scale , specifiying what kind of moments to compute. Default
is scale . |
moments
returns the features returned by cmoments
,
rmoments
and the features m.n20
, m.n11
,
m.n02
, m.theta
, m.l1
, m.l2
and
m.ecc
for each objet. See Definitions
for details
on features.
cmoments
returns the features m.pxs
, m.int
, m.x
and m.y
for each objet.
rmoments
returns Hu's translation/rotation/scale 7 invariant
moments m.Ik
for each object, where k spans from 1 to 7.
smoments
returns for each object the central moments mu_pq
if what
=central
or the scale invariant moments nu_pq if
what
=scale
. The variables (p, q) span the range [0, pw].
moments
, cmoments
and rmoments
returns a matrix
(or a list of matrices if x
contains multiple frames) of
features computed of the objects present in x
and using the
intensity values of ref
.
smoments
returns a 3-dimensional array of size (pw+1
,
pw+1
, n
) where n
is the maximal value of
x
, or a list of such arrays if x
contains multiple frames.
Image moments m_pq are defined for the k-th object in x
by:
m_pq = sum_{i,j st. x_ij = k} i^p * j^q * ref_ij.
Central moments mu_pq are defined for the k-th object in x
by:
mu_{pq} = sum_{i,j st. x_ij = k} (i - m_10/m_00)^p * (j -
m_01/m_00)^q * ref_{ij}. Central moments are invariant by translation.
Scale moments nu_pq are defined for the k-th object in x
by:
nu_{pq} = mu_pq / mu_00^(1+ (p+q)/2). Scale moments are
invariant by translation and scaling.
Features returned by moments
, cmoments
and
rmoments
are defined by:
m.pxs
= sum_{i,j st. x_ij = k} 1
m.int
= m_00
m.x
= m_10 / m_00
m.y
= m_01 / m_00
m.n20
= nu_20
m.n11
= nu_11
m.n02
= nu_02
m.theta
= 0.5 * atan(2*mu_11/(mu_20-mu_02))
m.l1
= largest eigenvalue of the covariance matrix [mu_20, mu_11 ;
mu_11, mu_02]/m_00
m.l2
= smallest eigenvalue of the covariance matrix
m.ecc
= sqrt(1-m.l2/m.l1)
m.Ik
= k-th Hu's moment, see References.
Properties:
m.pxs
is the surface of the objects, in pixels.
m.int
is the mass of the object.
m.x
, m.y
) is the center of gravity of the object.
m.n20
, m.n11
and m.n02
are translation/scale
invariant moments.
m.theta
characterizes the orientation of an object in radians.
m.l1
) and 2*sqrt(m.l2
) are the semi-major
and semi-minor axes of the object and have the dimension of a length.
m.Ik
is the translation/scale/rotation invariant k-th Hu's moment.
Oleg Sklyar, osklyar@ebi.ac.uk, 2007
M. K. Hu, Visual Pattern Recognition by Moment Invariants, IRE Trans. Info. Theory, vol. IT-8, pp.179-187, 1962
Image moments: http://en.wikipedia.org/wiki/Image_moments
getFeatures
, bwlabel
, watershed
, propagate
## load cell nucleus images x = readImage(system.file('images', 'nuclei.tif', package='EBImage')) if (interactive()) display(x) ## computes object mask y = thresh(x, 10, 10, 0.05) y = opening(y, makeBrush(5, shape='disc')) mask = fillHull(bwlabel(y)) if (interactive()) display(mask, title='Cell nuclei') ## moments m = moments(mask, x) mc = do.call(rbind, m) print(mc[1:5,]) cat('Mean nucleus size is', mean(mc[,'m.pxs']), '\n') cat('Mean nucleus eccentricity is', mean(mc[,'m.ecc']), '\n') ## paint nuclei with an eccentricity higher than 0.85 maskb = mask for (i in 1:dim(mask)[3]) { id = which(m[[i]][,'m.ecc']<0.85) z = maskb[,,i] z[!is.na(match(z, id))] = 0 maskb[,,i] = z } img = paintObjects(maskb, channel(x, 'rgb'), col=c(NA, 'red'), opac=c(0,0.7)) if (interactive()) display(img, title='Nuclei with high eccentricity')