moments {EBImage}R Documentation

Image moments and moment invariants

Description

Computes moments and invariant moments from image objects.

Usage

  moments(x, ref)
  cmoments(x, ref)
  rmoments(x, ref)
  smoments(x, ref, pw=3, what="scale")

Arguments

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.

Details

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].

Value

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.

Definitions

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:

Properties:

Author(s)

Oleg Sklyar, osklyar@ebi.ac.uk, 2007

References

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

See Also

getFeatures, bwlabel, watershed, propagate

Examples

  ## 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')

[Package EBImage version 3.0.5 Index]