Search code examples
matlabglcm

Matlab Co-occurrence Matrix


I'm sure this is a very simple mistake by me somewhere! But when I use Matlab's graycomatrix function, I don't get the expected result. Instead of a matrix output I expect, I always get an 8 x 8 (nearly) zero matrix with one entry in the bottom right - usually equal to 16. I haven't changed the default settings or used 'offset', so I'm not too sure what the problem is.


Solution

  • That's because your image is not normalized!

    Your image should be range 0-1, so:

    I = [1 1 2; 2 2 3; 1 2 5]; %or any other I
    glcm = graycomatrix(I/max(I(:))); % or I/255 , but it would not work for this example
    

    should do the job.

    In your case, Matlab interprets that everything avobe 1 is 1, therefore the co-occurrence matrix gives you a unique value in the max position.