To create a GLCM, use the
graycomatrix function. The function
creates a gray-level co-occurrence matrix (GLCM) by calculating how often a pixel with
the intensity (gray-level) value i occurs in a specific spatial
relationship to a pixel with the value j. By default, the spatial
relationship is defined as the pixel of interest and the pixel to its immediate right
(horizontally adjacent), but you can specify other spatial relationships between the two
pixels. Each element (i,j) in the resultant
is simply the sum of the number of times that the pixel with value
i occurred in the specified spatial relationship to a pixel
with value j in the input image.
The number of gray levels in the image determines the size of the GLCM. By default,
graycomatrix uses scaling to reduce the number of intensity
values in an image to eight, but you can use the
NumLevels and the
GrayLimits parameters to control this scaling of gray levels. See
graycomatrix reference page for more information.
The gray-level co-occurrence matrix can reveal certain properties about the spatial distribution of the gray levels in the texture image. For example, if most of the entries in the GLCM are concentrated along the diagonal, the texture is coarse with respect to the specified offset. You can also derive several statistical measures from the GLCM. See Derive Statistics from GLCM and Plot Correlation for more information.
To illustrate, the following figure shows how
calculates the first three values in a GLCM. In the output GLCM, element (1,1) contains
1 because there is only one instance in the input image
where two horizontally adjacent pixels have the values
glcm(1,2) contains the value
2 because there are two instances where two horizontally adjacent
pixels have the values
2. Element (1,3) in
the GLCM has the value 0 because there are no instances of two horizontally adjacent
pixels with the values 1 and 3.
graycomatrix continues processing the
input image, scanning the image for other pixel pairs (i,j) and
recording the sums in the corresponding elements of the GLCM.
Process Used to Create the GLCM