skimage2.feature.graycomatrix#
- skimage2.feature.graycomatrix(image, distances, angles, levels=None, symmetric=False, normed=False)[source]#
Calculate the gray-level co-occurrence matrix.
A gray level co-occurrence matrix is a histogram of co-occurring grayscale values at a given offset over an image.
Changed in version 0.19:
greymatrixwas renamed tograymatrixin 0.19.- Parameters:
- imagearray_like
Integer typed input image. Only positive valued images are supported. If type is other than uint8, the argument
levelsneeds to be set.- distancesarray_like
List of pixel pair distance offsets.
- anglesarray_like
List of pixel pair angles in radians.
- levelsint, optional
The input image should contain integers in [0,
levels-1], where levels indicate the number of gray-levels counted (typically 256 for an 8-bit image). This argument is required for 16-bit images or higher and is typically the maximum of the image. As the output matrix is at leastlevelsxlevels, it might be preferable to use binning of the input image rather than large values forlevels.- symmetricbool, optional
If True, the output matrix
P[:, :, d, theta]is symmetric. This is accomplished by ignoring the order of value pairs, so both (i, j) and (j, i) are accumulated when (i, j) is encountered for a given offset. The default is False.- normedbool, optional
If True, normalize each matrix
P[:, :, d, theta]by dividing by the total number of accumulated co-occurrences for the given offset. The elements of the resulting matrix sum to 1. The default is False.
- Returns:
- P4-D ndarray
The gray-level co-occurrence histogram. The value
P[i,j,d,theta]is the number of times that gray-leveljoccurs at a distancedand at an anglethetafrom gray-leveli. IfnormedisFalse, the output is of type uint32, otherwise it is float64. The dimensions are: levels x levels x number of distances x number of angles.
References
[1]M. Hall-Beyer, 2007. GLCM Texture: A Tutorial https://prism.ucalgary.ca/handle/1880/51900 DOI:
10.11575/PRISM/33280[2]R.M. Haralick, K. Shanmugam, and I. Dinstein, âTextural features for image classificationâ, IEEE Transactions on Systems, Man, and Cybernetics, vol. SMC-3, no. 6, pp. 610-621, Nov. 1973. DOI:10.1109/TSMC.1973.4309314
[3]M. Nadler and E.P. Smith, Pattern Recognition Engineering, Wiley-Interscience, 1993.
[4]Wikipedia, https://en.wikipedia.org/wiki/Co-occurrence_matrix
Examples
Compute 4 GLCMs using 1-pixel distance and 4 different angles. For example, an angle of 0 radians refers to the neighboring pixel to the right; pi/4 radians to the top-right diagonal neighbor; pi/2 radians to the pixel above, and so forth.
>>> image = np.array([[0, 0, 1, 1], ... [0, 0, 1, 1], ... [0, 2, 2, 2], ... [2, 2, 3, 3]], dtype=np.uint8) >>> result = graycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], ... levels=4) >>> result[:, :, 0, 0] array([[2, 2, 1, 0], [0, 2, 0, 0], [0, 0, 3, 1], [0, 0, 0, 1]], dtype=uint32) >>> result[:, :, 0, 1] array([[1, 1, 3, 0], [0, 1, 1, 0], [0, 0, 0, 2], [0, 0, 0, 0]], dtype=uint32) >>> result[:, :, 0, 2] array([[3, 0, 2, 0], [0, 2, 2, 0], [0, 0, 1, 2], [0, 0, 0, 0]], dtype=uint32) >>> result[:, :, 0, 3] array([[2, 0, 0, 0], [1, 1, 2, 0], [0, 0, 2, 1], [0, 0, 0, 0]], dtype=uint32)