56 views (last 30 days)

Show older comments

I need to extract GLCM features like energy entropy contrast among others of the REGION OF INTEREST ONLY excluding the black background,i managed to extract those features for the entire image but i only need them for the region of interest knowing that everything else will be black

% Loop over all GLCMs

for k = 1:nglcm

currentGLCM = glcm(:,:,k);

glcmMean(k) = mean2(currentGLCM);

% For symmetric GLCMs, uX = uY

uX(k) = sum(I.*currentGLCM(sub));

uY(k) = sum(J.*currentGLCM(sub));

sX(k) = sum((I-uX(k)).^2.*currentGLCM(sub));

sY(k) = sum((J-uY(k)).^2.*currentGLCM(sub));

out.contrast(k) = sum(abs(I-J).^2.*currentGLCM(sub)); %OK

out.dissimilarity(k) = sum(abs(I - J).*currentGLCM(sub)); %OK

out.energy(k) = sum(currentGLCM(sub).^2); % OK

out.entropy(k) = -nansum(currentGLCM(sub).*log(currentGLCM(sub))); %OK

out.inverseDifference(k) = sum(currentGLCM(sub)./( 1 + abs(I-J) )); %OK

out.homogeneity(k) = sum(currentGLCM(sub)./( 1 + (I - J).^2)); %OK

Phuong Nguyen
on 3 Apr 2020

Binu
on 8 May 2020

Force all pixel values outside your region of interest as a 'NaN'. The graycomatrix methods by default ignores any pixel pairs having a 'NaN' value.

https://www.mathworks.com/help/images/ref/graycomatrix.html#namevaluepairarguments (read Algorithms section)

Binu
on 4 Aug 2017

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!