Image Processing Toolbox User's Guide Previous page   Next Page
graycomatrix

Gray-level co-occurrence matrix from an image

Syntax

Description

glcms = graycomatrix(I) creates a gray-level co-occurrence matrix (GLCM) from image I. graycomatrix creates the GLCM by calculating how often a pizel 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 -- see Parameters.) 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.

Because the processing required to calculate a GLCM for the full dynamic range of an image is prohibitive, graycomatrix scales the values in I. If I is a binary image, graycomatrix scales the image to two levels. If I is an intensity image, graycomatrix scales it to eight levels. The number of gray-levels determines the size of the GLCM. You can specify the number of gray-levels in the GLCM using the 'NumLevels' parameter, and the way that graycomatrix scales the values using the 'GrayLimits' parameter -- see Parameters.

The following figure shows how graycomatrix calculates the value of glcm(1,1). This element contains the value 1 because there is only one instance in the image where two, horizontally adjacent pixels have the values 1 and 1. As the figure shows, glcm(1,2) contains the value 2 because there are two instances where two, horizontally adjacent pixels have the values 1 and 2.

glcms = graycomatrix(I,param1,val1,param2,val2,...) returns one or more gray-level co-occurrence matrices, depending on the values of the optional parameter/value pairs. Parameter names can be abbreviated, and case does not matter.

Parameters

The following table lists these parameters in alphabetical order.

Parameter
Description
Default
'GrayLimits'
A two-element vector, [low high], that specifies how the grayscale values in I are linearly scaled into gray levels. Grayscale values less than or equal to low are scaled to 1. Grayscale values greater than or equal to high are scaled to NumLevels. If graylimits is set to [], graycomatrix uses the minimum and maximum grayscale values in the image as limits, [min(I(:)) max(I(:))].
Minimum and maximum specified by class, e.g.
double [0 1]
int16
[-32768 32767]
'NumLevels'
An integer specifying the number of gray-levels to use when scaling the grayscale values in I. For example, if NumLevels is 8, graycomatrix scales the values in I so they are integers between 1 and 8. The number of gray-levels determines the size of the gray-level co-occurrence matrix (glcm).
8 (numeric)
2 (binary)
'Offset'
A p-by-2 array of integers specifying the distance between the pixel of interest and its neighbor. Each row in the array is a two-element vector, [row_offset, col_offset], that specifies the relationship, or offset, of a pair of pixels. 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. Because the offset is often expressed as an angle, the following table lists the offset values that specify common angles, given the pixel distance D.

Angle        Offset
  0              [0 D]
 45             [-D D]
 90             [-D 0]
135            [-D -D]

The figure illustrates the array: offset = [0 1; -1 1; -1 0; -1 -1]



[0 1]

[glcm, SI] = graycomatrix(...) returns the scaled image, SI, used to calculate the gray-level co-occurrence matrix. The values in SI are between 1 and NumLevels.

Class Support

I can be numeric or logical but must be two-dimensional, real, and nonsparse. SI is a double matrix having the same size as I. glcms is a 'NumLevels'-by-'NumLevels'-by-P double array where P is the number of offsets in 'Offset'.

Notes

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

graycomatrix ignores pixel pairs if either of the pixels contains a NaN.

graycomatrix 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.

Example

Calculate the gray-level co-occurrence matrix and return the scaled version of the image, SI, used by graycomatrix to generate the GLCM.

Calculate the gray-level co-occurrence matrix for the grayscale image, circuit.tif.

See Also

graycoprops


Previous page  gray2ind graycoprops Next page

© 1994-2005 The MathWorks, Inc.