Main Content

Texture Analysis Using Gray-Level Co-Occurrence Matrix

A gray-level co-occurrence matrix (GLCM) is a statistical method of examining texture. Unlike other texture filter functions, described in Calculate Statistical Measures of Texture, GLCMs consider the spatial relationships of pixels. A GLCM characterizes image texture by counting how often pixels with a certain intensity value occur in a specific spatial relationship to pixels with other intensity values.

A GLCM can reveal certain properties about the spatial distribution of the gray levels in a texture image. For example, if most of the entries in a GLCM are concentrated along the diagonal, then the texture is coarse with respect to the specified offset. You can also derive several statistical measures from a GLCM. See Derive Statistics from GLCM and Plot Correlation for more information.

Create a Gray-Level Co-Occurrence Matrix

To create a GLCM, use the graycomatrix function. By default, the graycomatrix function creates a single GLCM, in which the spatial relationship consists of the pixel of interest and the pixel to its immediate right. In the default GLCM, each element (i, j) is the count of the number of times that a pixel with gray level i occurs to the left of a pixel with gray level j in the input image.

To illustrate, the figure shows how graycomatrix calculates the first three values in a GLCM with the default spatial relationship:.

  • Element (1, 1) in the GLCM contains the value 1. There is only one instance in the input image where a pixel with the value 1 is directly to the left of another pixel with the value 1.

  • Element (1, 2) in the GLCM contains the value 2. There are two instances where a pixel with the value 1 is directly to the left of a pixel with the value 2.

  • Element (1, 3) in the GLCM contains the value 0. There are no instances in the input image where a pixel with the value 1 is directly to the left of a pixel with the value 3.

graycomatrix continues processing the input image, scanning the image for other pixel pairs (i, j) and recording the counts in the corresponding elements of the GLCM.

Process Used to Create the GLCM

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. To control the scaling of gray levels, you can use the NumLevels and the GrayLimits name-value arguments.

Specify Offset Used in GLCM Calculation

A single GLCM might not be enough to describe the textural features of the input image. For example, a single horizontal offset might not be sensitive to texture with a vertical orientation. To obtain additional information about textural features, you can create multiple GLCMs with different spatial relationships between pixels.

To create multiple GLCMs, specify a matrix of offsets to the graycomatrix function. These offsets define pixel relationships of varying direction and distance. For example, you can define a matrix of offsets that specify four directions (horizontal, vertical, and two diagonals) and four distances. In this case, the input image is represented by 16 GLCMs. When you calculate statistics from these GLCMs, you can take the average.

Specify the offsets as a 2-column matrix of integers. Each row in the matrix has the form [row_offset col_offset], and specifies one offset. row_offset is the number of rows between the pixel of interest and its neighbor. col_offset is the number of columns between the pixel of interest and its neighbor.

This sample code creates a matrix of offsets for four directions and four distances in each direction.

offsets = [ 0  1;  0  2;  0  3;  0  4; ...     % four offsets in the horizontal direction
           -1  1; -2  2; -3  3; -4  4; ...  % four offsets in the 45 degree diagonal direction
           -1  0; -2  0; -3  0; -4  0; ...  % four offsets in the vertical direction
           -1 -1; -2 -2; -3 -3; -4 -4]; % four offsets in the 135 degree diagonal direction

This figure illustrates the spatial relationships of pixels that are defined by this array of offsets, where D represents the distance from the pixel of interest.

Derive Statistics from GLCM

After you create GLCMs, you can derive several statistics from them by using the graycoprops function. These statistics provide information about the texture of an image. This table lists the statistics.

Statistic

Description

Contrast

Measures the local variations in the gray-level co-occurrence matrix.

Correlation

Measures the joint probability occurrence of the specified pixel pairs.

Energy

Provides the sum of squared elements in the GLCM. Also known as uniformity or the angular second moment.

Homogeneity

Measures the closeness of the distribution of elements in the GLCM to the GLCM diagonal.

See Also

|

Topics