Image Processing Toolbox User's Guide |
Gray-level co-occurrence matrix from an image
Syntax
glcm = graycomatrix(I) glcms = graycomatrix(I,param1,val1,param2,val2,...) [glcms,SI] = graycomatrix(...)
Description
creates a gray-level co-occurrence matrix (GLCM) from image I. glcms = graycomatrix(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.
[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
gray2ind | graycoprops |
© 1994-2005 The MathWorks, Inc.