Main Content

Create a Gray-Level Co-Occurrence Matrix

To create a GLCM, use thegraycomatrixfunction. The function creates a gray-level co-occurrence matrix (GLCM) by calculating how often a pixel with the intensity (gray-level) valueioccurs in a specific spatial relationship to a pixel with the valuej。默认情况下,定义了空间关系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 resultantglcmis simply the sum of the number of times that the pixel with valueioccurred in the specified spatial relationship to a pixel with valuejin the input image.

The number of gray levels in the image determines the size of the GLCM. By default,graycomatrixuses scaling to reduce the number of intensity values in an image to eight, but you can use theNumLevelsand theGrayLimitsparameters to control this scaling of gray levels. See thegraycomatrixreference 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. SeeDerive Statistics from GLCM and Plot Correlationfor more information.

To illustrate, the following figure shows howgraycomatrixcalculates the first three values in a GLCM. In the output GLCM, element (1,1) contains the value1because there is only one instance in the input image where two horizontally adjacent pixels have the values1and1, respectively.glcm(1,2)contains the value2because there are two instances where two horizontally adjacent pixels have the values1and2。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.graycomatrixcontinues 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