"Karthik " <
karth...@gmail.com> wrote in message <k6u9bn$eu5$
1...@newscl01ah.mathworks.com>...
Hi Karthik, if I'm correct, the idea is to take into consideration only the pixels that are inside your ROI. Matlab has a build in function called graycomatrix, which computes de co-ocurrence gray level matrix but that function does not accept mask as an argument.
However, if you input the command >>edit graycomatrix in matlab, you will see the matlab code that actually runs that algorithm. There, you can see how this function will ignore any NaN values present in your image. Knowing that, it's easy to put the pixels outside your mask or ROIs to NaN and let graycomatrix do his magic.
I'm leaving here a function I'm using now:
function [c cor e h] = graycomatrix_descriptor( image, mask )
% First thing to do is put the values of image outside mask = NaN. This is because
% the matlab function graycomatrix will ignore NaN values when computing GLCM
image = double(image);
image(~mask) = NaN;
% Now get GLCM
kernel = [0 1; 0 -1; 1 0; -1 0];
warning('off','Images:graycomatrix:scaledImageContainsNan');
glcm = graycomatrix( image, 'NumLevels', 8, 'GrayLimits', [],'offset', kernel );
stats = graycoprops( glcm, 'Contrast Correlation Energy Homogeneity');
warning('on','Images:graycomatrix:scaledImageContainsNan');
c = mean( stats.Contrast );
cor = mean( stats.Correlation );
e = mean( stats.Energy );
h = mean( stats.Homogeneity );
end
Hope this helps
Tomás.