Automatic Mask for multiple Images
4 ビュー (過去 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!