Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Automatic Mask for multiple Images
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Gaurav Garg
am 24 Apr. 2020
Hey Donnell,
Can you upload your sample image as image masking techniques vary from image to image?
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!