Based on the theoretical knowledge of gray level co-occurrence matrix, use skimage to extract the texture features of digital images

Because the gray-level co-occurrence matrix is ​​recently used to extract the texture features of the image, it is necessary to describe this theory. The gray level co-occurrence matrix, also known as the joint probability matrix method, is a method to describe the texture information by the probability of a certain gray level structure in the image recurring. This method uses conditional probability to extract texture features, and constructs a matrix by the probability of occurrence of gray value pairs of a pair of pixels with a certain positional relationship (direction and distance between pixels) in statistics space, and then extracts meaningful texture from the matrix. The statistical characteristics to describe the texture. It is not suitable to talk too much about the theory. Next, I will describe how to extract the texture features of a picture according to the order of extracting texture features.

First introduce a library scikit-image, the access URL is below, which is a magic weapon for extracting gray-level co-occurrence matrix and texture features:

https://scikit-image.org/

1. Image gray level degradation

Before extracting texture features, it is very necessary to downgrade the gray level of the image. The size of the gray level co-occurrence matrix is ​​also equal to the size of the gray level. If the gray level is too large, it will lead to gray level co-occurrence If the matrix is ​​too large, it will lead to a particularly large amount of calculation, which will cause the program to run for a long time. At the same time, the effect does not mean that the larger the gray-scale co-occurrence matrix, the better the effect will be. The gray-scale co-occurrence matrix needs to be selected according to the actual situation. Size, commonly used gray levels are 3, 4 to 16 and so on.

2. Calculate the gray level co-occurrence matrix

At this time, we will use the magic weapon introduced above, skimage.graymatrix, citing an example in the official website of skimage to explain

>>> image = np.array([[0, 0, 1, 1],
...                   [0, 0, 1, 1],
...                   [0, 2, 2, 2],
...                   [2, 2, 3, 3]], dtype=np.uint8)
>>> g = graycomatrix(image, [1, 2], [0, np.pi/2], levels=4,
...                  normed=True, symmetric=True)
>>> contrast = graycoprops(g, 'contrast')
>>> contrast
array([[0.58333333, 1.        ],
       [1.25      , 2.75      ]])

At this time, the image input above is a picture that has been degraded in gray level, and the gray level at this time is 4

skimage.feature.graycomatrix(imagedistancesangleslevels=Nonesymmetric=Falsenormed=False)

image: the image that has been degraded to grayscale

distances: the distance between pixels when generating the co-occurrence matrix

angles: The direction generated by the gray-level co-occurrence matrix can be 0°, 45°, 90°, 135°, and multiple angles can be stored in the form of a list. In the above example, only two aspects are extracted.

symmetric: statistics of forward results, or both forward and reverse results

 Then use skimage.feature.graycoprops to extract features

The following features are given on the official website:

The display is not comprehensive, you can consider visiting this URL

Module: feature — skimage v0.19.2 docs (scikit-image.org)  

Take a chestnut:

If you want to extract ASM

Just enter the command statement below:
 

skimage.feature.graycoprops(P, prop='ASM')

P is the grayscale co-occurrence matrix extracted by graycomatrix, and different texture feature values ​​can be extracted by assigning different values ​​to prop.

The texture feature values ​​currently provided by skimage are:

contrast’, ‘dissimilarity’, ‘homogeneity’, ‘energy’, ‘correlation’, ‘ASM’

This article mainly describes how to use the skimage library to extract texture features, which is much more convenient than handwriting the program to extract texture features. For the specific theoretical knowledge of the gray level co-occurrence matrix, readers can check the digital image processing book by themselves. 

Guess you like

Origin blog.csdn.net/kuwola/article/details/123568627