Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Automatic Mask for multiple Images
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Gaurav Garg
le 24 Avr 2020
Hey Donnell,
Can you upload your sample image as image masking techniques vary from image to image?
Réponses (0)
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!