Info
此问题已关闭。 请重新打开它进行编辑或回答。
Automatic Mask for multiple Images
1 次查看(过去 30 天)
显示 更早的评论
My goal is to have my code generate a mask around a cell automatically. Right now I have to create the mask using
hFH = drawassisted() maskImage = hFH.createMask();.
Is there a way for me to generate this mask automatically for different images based on a range of pixel values? This is my current code
myFolder = 'C:\Users\x\Desktop\images';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
I = rgb2gray(imread(fullFileName));
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]);
set(gcf,'name','Analysis of Texture Features of Cervical Cells','numbertitle','off')
subplot(1, 2, 2);
hFH = drawassisted()
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)
f = figure;
uit = uitable(f);
d = {'Contrast',stats_maskImage.Contrast;'Correlation',stats_maskImage.Correlation;'Energy',stats_maskImage.Energy,;'Homogeneity',stats_maskImage.Homogeneity;};
uit.Data = d;
uit.Position = [20 20 258 78];
if stats_maskImage.Energy<0.8700
imshow(blackMaskedImage)
title('Abnormal', 'FontSize', fontSize)
elseif(0.9600<stats_maskImage.Energy)
imshow(blackMaskedImage)
title('Error! Please Try Drawing Mask Again', 'FontSize', fontSize)
else
imshow(blackMaskedImage)
title('Normal','FontSize', fontSize)
end
pause(10)
end
1 个评论
Gaurav Garg
2020-4-24
Hey Donnell,
Can you upload your sample image as image masking techniques vary from image to image?
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!