Using a sliding window with GLCM

user3851917 picture user3851917 · Jul 18, 2014 · Viewed 7.6k times · Source

I'm trying to calculate various image features from the Gray-Level Co-occurence Matrix (GLCM) in MatLab using the graycomatrix function.

Example using graycomatrix

I = [0 0 1 1; 0 0 1 1; 0 2 2 2; 2 2 3 3];
glcm = graycomatrix(I, 'GrayLimits', [0 3], 'NumLevels', 4, 'Symmetric', true);

How can I apply this function to a series of sub-windows assuming a larger image (640x480 for example) than the trivial example and a sliding window size of 5x5?

Answer

fyts picture fyts · Jul 18, 2014

I'm not sure a filtering approach is possible. I think you mean sth like this (let im be your grayscale image):

for ii=3:size(im,1)-2
    for jj=3:size(im,2)-2  % a loop for every pixel that a 5x5 window can be defined
        temp_im=im(ii-2:ii+2,jj-2:jj+2);  % crop a small window around pixel
        glcm=graycomatrix(temp_im);  % default parameters
        glcm_feat_struct=graycoprops(glcm);
        % extract features from struct and do anything you want
    end
end