\HeaderA{haralickMatrix}{Co-occurrence matrices (GLCM) and Haralick texture features}{haralickMatrix}
\aliasA{haralickFeatures}{haralickMatrix}{haralickFeatures}
\begin{Description}\relax
Computes the gray level co-occurrence matrix (GLCM, frequency of
pixel intensities given the mean intensity of their 4 neighbouring pixels)
and corresponding Haralick features from image objects.
\end{Description}
\begin{Usage}
\begin{verbatim}
  haralickFeatures(x, ref, nc = 32)
  haralickMatrix(x, ref, nc = 32)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{Image} object or an array containing object masks.
Object masks are sets of pixels with the same unique integer value.
\item[\code{ref}] An \code{Image} object or an array, containing the
intensity values of the objects.
\item[\code{nc}] A numeric value. Specifies the number of gray levels
used to compute the co-occurrence matrix. Default value is 32.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{haralickFeatures} computes the following set of statistics on
the GLCM matrix:

\Itemize{
\item[\code{h.asm}] Angular second moment: \code{sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc]p(i,j)\textasciicircum{}2}.
\item[\code{h.con}] Contrast: \code{sum[i=2\textasciicircum{}(2*nc)] n\textasciicircum{}2 *
    sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] p(i,j), for all i,j s.t ABS(i - j) = n}.
\item[\code{h.cor}] Correlation: \code{sum[i=1\textasciicircum{}nc]
    sum[j=1\textasciicircum{}nc]((i * j) * p(i,j) - mu\_x * mu\_y) / sigma\_x * sigma\_y}.
\item[\code{h.var}] Variance: \code{sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc](i - mu)\textasciicircum{}2.
    * p(i,j)}.
\item[\code{h.idm}] Inverse difference moment: \code{sum[i=1\textasciicircum{}nc]
    sum[j=1\textasciicircum{}nc] p(i,j) / (1 + (i - j)\textasciicircum{}2) }.
\item[\code{h.sav}] Sum average: \code{sum[i=2\textasciicircum{}(2*nc)] i * Px+y(i)}.
\item[\code{h.sva}] Sum variance: \code{sum[i=2\textasciicircum{}(2*nc)] (i - sen)\textasciicircum{}2 * Px+y(i)}.
\item[\code{h.sen}] Sum entropy: \code{-sum[i=2\textasciicircum{}(2*nc)] Px+y(i) * log(p(i,j))}.
\item[\code{h.ent}] Entropy: \code{-sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] p(i,j) *
    log( p(i,j) )}.
\item[\code{h.dva}] Difference variance: \code{sum[i=0\textasciicircum{}(nc-1)] (i\textasciicircum{}2) * Px-y(i)}.
\item[\code{h.den}] Difference entropy: \code{sum[i=0\textasciicircum{}(nc-1)] Px-y(i)
      * log( Px-y(i,j) )}.
\item[\code{h.f12}] Measure of correlation: \code{abs(ent - HXY1) / HX}.
\item[\code{h.f13}] Measure of correlation: \code{sqrt( 1 - exp(2*(ent - HXY2)))}.
}

where:
\Itemize{
\item[\code{p}] is the GLCM matrix.
\item[\code{Px(i)}] Marginal frequency. Defined by \code{Px(i) = sum[j=1\textasciicircum{}nc] p(i,j)}.
\item[\code{Py(j)}] Marginal frequency. Defined by \code{Py(j) = sum[i=1\textasciicircum{}nc] p(i,j)}.
\item[\code{mu\_x, mu\_y}] Means of \code{Px} and \code{Px}.
\item[\code{sigma\_x, sigma\_y}] Standard deviations of \code{Px} and \code{Py}.
\item[\code{Px+y}] Probability of the co-occurrence matrix
coordinates sums to \code{x+y}. Defined by \code{Px+y(k) =
        sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] p(i,j), i + j = k and k = 2,3,...,2*nc}.
\item[\code{Px-y}] Probability of the absolute value of the
difference between co-occurrence matrix cooordinates being equal
to \code{x-y}. Defined by \code{Px-y(k) = sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] p(i,j), abs(i - j) = k and k =
        2,3,...,2*nc}.
\item[\code{HXY1}] \code{-sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] p(i,j) * log(
        Px(i),Py(j))}.
\item[\code{HXY2}] \code{-sum[i=1\textasciicircum{}nc] sum[j=1\textasciicircum{}nc] Px(i)*Py(j) * log(
        Px(i),Py(j))}.
}

Computed Haralick features are rotational invariant and good descriptors of
object textures.
\end{Details}
\begin{Value}
\code{haralickFeatures} returns a matrix (or a list of matrices if
\code{x} contains multiple frames) of features computed of the objects
present in \code{x} and using the intensity values of \code{ref}.

\code{haralickMatrix} returns an array (or a list of arrays if
\code{x} contains multiple frames) of dimension \code{nc*nc*nobj},
where \code{nobj} is the number of objects  in \code{x}, containing
the GLCM values of image objects.
\end{Value}
\begin{Author}\relax
Mike Smith, \email{msmith@ebi.ac.uk}; Oleg Sklyar, \email{osklyar@ebi.ac.uk}, 2007
\end{Author}
\begin{References}\relax
R. M. Haralick, K Shanmugam and Its'Hak Deinstein (1979). \emph{Textural Features for Image 
Classification}. IEEE Transactions on Systems, Man and Cybernetics.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{getFeatures}{getFeatures}}, \code{\LinkA{zernikeMoments}{zernikeMoments}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  example(getFeatures)
\end{ExampleCode}
\end{Examples}

