greycomatrix
-
skimage.feature.greycomatrix(image, distances, angles, levels=256, symmetric=False, normed=False)
[source] -
Calculate the grey-level co-occurrence matrix.
A grey level co-occurrence matrix is a histogram of co-occurring greyscale values at a given offset over an image.
Parameters: image : array_like of uint8
Integer typed input image. The image will be cast to uint8, so the maximum value must be less than 256.
distances : array_like
List of pixel pair distance offsets.
angles : array_like
List of pixel pair angles in radians.
levels : int, optional
The input image should contain integers in [0, levels-1], where levels indicate the number of grey-levels counted (typically 256 for an 8-bit image). The maximum value is 256.
symmetric : bool, 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.normed : bool, 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: P : 4-D ndarray
The grey-level co-occurrence histogram. The value
P[i,j,d,theta]
is the number of times that grey-levelj
occurs at a distanced
and at an angletheta
from grey-leveli
. Ifnormed
isFalse
, the output is of type uint32, otherwise it is float64.References
[R147] The GLCM Tutorial Home Page, http://www.fp.ucalgary.ca/mhallbey/tutorial.htm [R148] Pattern Recognition Engineering, Morton Nadler & Eric P. Smith [R149] Wikipedia, http://en.wikipedia.org/wiki/Co-occurrence_matrix Examples
Compute 2 GLCMs: One for a 1-pixel offset to the right, and one for a 1-pixel offset upwards.
>>> image = np.array([[0, 0, 1, 1], ... [0, 0, 1, 1], ... [0, 2, 2, 2], ... [2, 2, 3, 3]], dtype=np.uint8) >>> result = greycomatrix(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)
Please login to continue.