Create gray-level co-occurrence matrix from image

creates
a gray-level co-occurrence matrix (GLCM) from image `glcms`

= graycomatrix(`I`

)`I`

. Another
name for a gray-level co-occurrence matrix is a *gray-level spatial
dependence matrix*.

`graycomatrix`

creates the GLCM by calculating
how often a pixel with gray-level (grayscale intensity) value *i* occurs
horizontally adjacent to a pixel with the value *j*.
(You can specify other pixel spatial relationships using the `'Offsets'`

parameter.)
Each element (*i,j*) in `glcm`

specifies
the number of times that the pixel with value *i* occurred
horizontally adjacent to a pixel with value *j*.

returns one or more gray-level co-occurrence matrices, depending on the values of
the optional name-value pair arguments.`glcms`

= graycomatrix(`I`

,`Name,Value`

)

`graycomatrix`

calculates the GLCM from a scaled
version of the image. By default, if `I`

is a binary
image, `graycomatrix`

scales the image to two gray-levels.
If `I`

is an intensity image, `graycomatrix`

scales
the image to eight gray-levels. You can specify the number of gray-levels `graycomatrix`

uses
to scale the image by using the `'NumLevels'`

parameter,
and the way that `graycomatrix`

scales the values
using the `'GrayLimits'`

parameter .

The following figure shows how `graycomatrix`

calculates
several values in the GLCM of the 4-by-5 image `I`

.
Element (1,1) in the GLCM contains the value `1`

because
there is only one instance in the image where two, horizontally adjacent
pixels have the values `1`

and `1`

.
Element `(1,2)`

in the GLCM contains the value `2`

because
there are two instances in the image where two, horizontally adjacent
pixels have the values `1`

and `2`

. `graycomatrix`

continues
this processing to fill in all the values in the GLCM.

`graycomatrix`

ignores pixel pairs if either
of the pixels contains a `NaN`

, replaces positive `Infs`

with
the value `NumLevels`

, and replaces negative `Infs`

with
the value `1`

. `graycomatrix`

ignores
border pixels, if the corresponding neighbor pixel falls outside the
image boundaries.

The GLCM created when `'Symmetric'`

is set
to `true`

is symmetric across its diagonal, and is
equivalent to the GLCM described by Haralick (1973). The GLCM produced
by the following syntax, with `'Symmetric'`

set to `true`

graycomatrix(I, 'offset', [0 1], 'Symmetric', true)

is equivalent to the sum of the two GLCMs produced by the following
statements where`'Symmetric'`

is set to `false`

.

graycomatrix(I, 'offset', [0 1], 'Symmetric', false) graycomatrix(I, 'offset', [0 -1], 'Symmetric', false)

[1] Haralick, R.M., K. Shanmugan, and I. Dinstein, "Textural Features for Image Classification", IEEE Transactions on Systems, Man, and Cybernetics, Vol. SMC-3, 1973, pp. 610-621.

[2] Haralick, R.M., and L.G. Shapiro. Computer and Robot Vision: Vol. 1, Addison-Wesley, 1992, p. 459.