Prerequisites Concept Calculation method
For high accuracy and fine-grained texture distribution, we take pixel spacing for d=1, the following is the direction of the description:
In our view, MATLAB built-in toolbox of gray-level co-occurrence matrix generation function Graycomatrix (gray-level co-occurrence matrix) on the direction of the description:
As shown in the figure above, the direction is obtained in the neighborhood of each pixel (pixel of interest) (except, of course, the boundary point), except that the coordinate system here becomes:
Δ= (0,±1) is a horizontal scan, i.e. θ=0∘orθ=180∘;δ= (±1,0) is a vertical scan (θ=90∘orθ=−90∘), δ= (1,−1), δ= (−1,1) is a −45∘ or 135∘ scan; δ= (1,1), δ= (−1,−1) It's a 45∘ scan.
The gray-scale co-occurrence matrix can be generated once the pixel distance between D and the spatial position of the pixel is determined.
GLCM represents some of the statistical characteristics of texture images, the so-called statistics, in layman's terms is to accumulate a certain number of times, with this number divided by the total number of cases, you can get the probability of its statistical significance.
Let's count the number of times gray Level 2 and 2 appear in the-45-and 135-degree directions (i.e. δ= (1,−1) or δ= (−1,1)), as shown, nine times, two in 18 directions.
MATLAB MATLAB related Toolbox function
Using the gray-level co-occurrence matrix (GLCM) to describe and extract image texture features is a powerful and popular tool, the natural MATLAB Toolbox will provide the corresponding function--graycomatrix:
The basic usage of the function is to give an image matrix, set some parameters and get its gray level co-occurrence matrix.
[GLCM, SI] = Graycomatrix (I, ...)
The main parameters are two, respectively, Numlevels (grayscale series)
The size of the final GLCM is numlevels*numlevels Offset (direction [0, 1;-1, 1;-1, 0;-1,-1]):
[0, 1] of the 1 offset (offset), of course, can also take 2 or more, as mentioned above, for the high precision and image texture itself is very rich in the image, in order to better depict the offset (offset) is 1.
We convert the original I to SI, and the value of the element in the SI calculation glcm,si between [1, Numlevels].
I = [
1 1 5 6 8 8;
2 3 5 7 0 2;
0 2 3 5 6 7
];
[GLCM, SI] = Graycomatrix (I, ' Numlevels ', 9, ' G ', [])
% ' Offset ' default value is ' [0, 1] '
GLCM =
0 0 2 0 0 0 0 0 0 0 1 0 0 0 1-0 0 0
0 0 , 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0
, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 , 0 2 1 0 0 0 0 0 0 0 0 1 1
1 0 , 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
SI =
2 2 6 7 9 9 3 4-6 8 1 3
1 3 4 6 7 8
Demo
Here to write a demo, a little bit difficult to understand is the gray-scale co-occurrence matrix calculation method, and then some programming on the circular judgment. The other directions have not been taken into account (may be slightly different in the third and fourth-tier loops), and the operation of encapsulating them into a function is left to later:
Clear, CLC
P = [0 1 2 0 1 2 1 2 0 1 2 0 2 0 1 2 0 1 0 1 2 0 1 2 1 2 0 1 2 0 2 0 1 2
];
[R, c] = size (P);
P_u = unique (P); % to go heavy, get all the gray level
n = length (P_u); % of different gray level number
G = zeros (n, n); % initialize gray-level co-occurrence matrix is full 0 matrix,
four-layer cycle, the outermost two-layer cycle is used for the GLCM of each position in the two-layer
loop to traverse the original image matrix, accumulated in accordance with a corresponding relationship between the number of occurrences for
p = 1:n,
for q = 1:n,
cnt = 0; % GLCM depicts the statistical characteristics of the pixel of grayscale image, and obtains the for i = 1:r in matlab, for
j = 1:c,
if (j+1) <= C && (P (i , j) = = P && p (i, j+1) = = q) | | P (i, j) = = Q && p (i, j+1) = = p),
cnt = cnt + 1;
End
End
G (p, q) = CNT;
End
End
G
References
[1] < image feature extraction--gray level co-occurrence matrix (GLCM) >