MATLAB: GLCM stats with a mask

glcm

I would like to evaluate the glcm features of the region of interest that in inside the mask. To only consider what is inside the mask I am attempting to multiply the original image by the mask and then take the glcm. I keep getting the same error.
I = rgb2gray(imread('5.jpg'))
imshow(I)
hFH = imfreehand()
xy = hFH.getPosition;
binaryImage = hFH.createMask();
blackMaskedImage = I;
blackMaskedImage(~binaryImage) = 0;
binaryImage=blackMaskedImage*blackMaskedImage(~binaryImage)
glcm_binaryImage=graycomatrix(binaryImage)
imshow(blackMaskedImage);
stats_binaryImage = graycoprops(glcm_binaryImage)

Best Answer

%%Working Code
fontSize = 20;I= rgb2gray(imread('C:\Users\x\Desktop\5.jpg'))
subplot(1, 2, 1);
imshow(I);
title('Original Image', 'FontSize', fontSize);
subplot(1, 2, 2);
imshow(I);
title('Draw Region Of Interest', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')subplot(1, 2, 2);
hFH = imfreehand()
maskImage = hFH.createMask();subplot(1, 2, 2);blackMaskedImage = I;
blackMaskedImage(~maskImage) = NaN;imshow(blackMaskedImage);title('Masked Image', 'FontSize', fontSize);maskedImage = I.* cast(maskImage, class(I));glcm_maskedImage=graycomatrix(maskedImage)
stats_maskImage = graycoprops(glcm_maskedImage)
Related Question