Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Grey Level Co-occurrence Matrix (GLCM) in MATLAB


Let’s see in these series of posts on how to extract the texture features from Grey Level Co-occurrence Matrix (GLCM) in MATLAB.  In simple terms, GLCM gives the spatial relationship between adjacent or neighbouring pixels. And from this GLCM Matrix, we will measure some texture features.

Let’s consider a simple example and start coding the steps in terms of algorithmic as well as programming in MATLAB.

Procedure to Generate GLCM Matrix:








MATLAB CODE:

clear all
%GLCM MATRIX

A=[1 2 3 2 3; 1 2 3 4 5; 4 4 1 1 4; 6 7 6 7 6; 1 8 1 8 8];

Displacement = 1; %NUMBER OF STEPS BETWEEN TWO PIXELS

NumQuantLevels = 8; %QUANTIZATION LEVEL
glcm = zeros([NumQuantLevels,NumQuantLevels]); %PREALLOCATE GLCM MATRIX

for i = 1:size(A,1)
    for j = 1 :size(A,2)-1
        glcm(A(i,j),A(i,j+1))=glcm(A(i,j),A(i,j+1))+1; %INCREMENT BY 1
    end

end


EXPLANATION:
The number of occurrences of a pixel and its neighboring pixel is calculated. The offset is 1 and it can be incremented based on the requirement. Here the direction of the pixel movement is towards the right. The maximum value of the pixel in the matrix A is 8 so the quantization level is fixed to 8. For instance, in the example given above, the pixel 2 and its neighbor 3 occurs 3 times in matrix A and it is updated in the GLCM matrix at the position (2,3) as 3.


Continue Reading: Texture Measures from GLCM - MATLAB CODE



like button Like "IMAGE PROCESSING" page
Previous Post Next Post Home
Google ping Hypersmash.com