\HeaderA{getFeatures}{Feature extraction for objects in indexed images}{getFeatures}
\aliasA{features}{getFeatures}{features}
\aliasA{features,IndexedImage-method}{getFeatures}{features,IndexedImage.Rdash.method}
\aliasA{getFeatures,IndexedImage-method}{getFeatures}{getFeatures,IndexedImage.Rdash.method}
\keyword{manip}{getFeatures}
\begin{Description}\relax
Functions to extract numerical descriptors for objects in indexed images.
The functions here call a set of individual feature extraction routines for
every feature set like hull, texture (Haralick), edge, moment features etc.
\end{Description}
\begin{Usage}
\begin{verbatim}

  ## S4 method for signature 'IndexedImage':
  getFeatures(x, ref, N=12, R=30, apply.Gaussian=TRUE, nc=256, ...)
  ## S4 method for signature 'IndexedImage':
  features(x, ...)

\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An object of \code{\LinkA{IndexedImage}{IndexedImage.Rdash.class}} (like those
obtained from \code{\LinkA{propagate}{propagate}} or \code{\LinkA{watershed}{watershed}}. 
\item[\code{ref}] A reference image containing images of the objects in
Grayscale mode (intensity values)! 
\item[\code{N}] Passed to \code{\LinkA{zernikeMoments}{zernikeMoments}}. Integer value 
defining the degree of the Zernike polynomials, which in turn defines the 
number of features calculated. Defaults to 12.
\item[\code{R}] Passed to \code{\LinkA{zernikeMoments}{zernikeMoments}}. Defines the radius 
of the circle around an object centre from which the features are calculated. 
It also defines the standard deviation for the 2D Gausian applied at the 
centre of an object. See details. Defaults to 30. 
\item[\code{apply.Gaussian}] Passed to \code{\LinkA{zernikeMoments}{zernikeMoments}}. A logical 
value that specifies if a local 2D Gaussian modification should be applied 
to every object at its centre. Defaults to \code{TRUE}.
\item[\code{nc}] Passed to \code{\LinkA{haralickFeatures}{haralickFeatures}}. A numeric value. 
Specifies the number of gray levels to separate \code{ref} into when 
calculating the co-occurrence matrix. Here defaults to 256.
\item[\code{...}] Reserved. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{ref} can be missing in calls to \code{getFeatures}. In this case texture
and other intensity-dependent features will be omitted.
\end{Details}
\begin{Value}
\code{getFeatures} calculates feature matrices and returns an object of 
\code{\LinkA{IndexedImage}{IndexedImage.Rdash.class}} with its \code{features} slot set. The typical
use would be to re-assign the result to the original image itself, 
i.e. \code{x <- getFeatures(x, a)}.

\code{features} extracts the content of the \code{features} slot of the 
\code{IndexedImage}. If it is empty, the function calls \code{getFeatures}
without a reference image and returns the generated feature set. In this
case the \code{features} slot of the original image is not updated.
\end{Value}
\begin{Author}\relax
Oleg Sklyar, \email{osklyar@ebi.ac.uk}, 2007
\end{Author}
\begin{SeeAlso}\relax
\code{
  \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class},
  \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class}, \LinkA{IndexedImage}{IndexedImage.Rdash.class},
  \LinkA{IndexedImage}{IndexedImage.Rdash.class}
}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

  ## load images
  f <- paste( system.file(package="EBImage"), "images/Gene1_G.tif", sep="/" )
  ii = readImage(f)
  ## normalize images
  ii = normalize(ii, separate=TRUE)
  ## segment
  mask = thresh(ii, 25, 25, 0.02)
  ## refine segmentation with morphology filters
  mk3 = morphKern(3)
  mk5 = morphKern(5)
  mask = dilate(erode(closing(mask, mk5), mk3), mk5)
  ## index objects with 'watershed'
  io = watershed( distmap(mask), 1.5, 1)
  ft = hullFeatures(io)
  mf = moments(io, ii)   ## need these for intensity and size
  for ( i in seq_along(ft) ) ft[[i]] = cbind(ft[[i]], mf[[i]])
  io = rmObjects(io, lapply(ft, function(x) 
         which(x[,"h.s"] < 150 | x[,"int"] < 50 | 0.3 * x[,"h.p"] < x[,"h.edge"] )
       ))
  io = getFeatures(io, ii)
  str( features(io) )
  
\end{ExampleCode}
\end{Examples}

