MATLAB: How to labels each cell in image? i upload the input images and the output masks which i wants from the input image.

i want to label(separate each cell) from the given image

1(110).png

Best Answer

Try this code to label the regions and loop through and show you the regions one at a time:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
binaryImage = imread('index.png');
subplot(2, 2, 1);
imshow(binaryImage); % Saved image is already logical/binary.
axis('on', 'image');
title('Original Binary Image', 'FontSize', fontSize);
filledImage = imfill(binaryImage,'holes');
subplot(2, 2, 2);
imshow(filledImage);
axis('on', 'image');
title('Filled Binary Image', 'FontSize', fontSize);
subplot(2, 2, 3);
[labeledImage, numberOfRegions] = bwlabel(filledImage);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
imshow(coloredLabels);
axis('on', 'image');
caption = sprintf('Labeled Image has %d Regions', numberOfRegions);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Make measurements
props = regionprops(labeledImage, 'Image', 'BoundingBox');
% Loop over all blobs, showing them one at a time.
subplot(2, 2, 4);
for k = 1 : numberOfRegions
thisBlob = props(k).Image;
imshow(thisBlob);
axis('on', 'image');
[rows, columns] = size(thisBlob);
caption = sprintf('Region #%d is %d rows by %d columns', k, rows, columns);
title(caption, 'FontSize', fontSize);
promptMessage = sprintf('Do you want to Continue,\nor Quit?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
break;
end
end
0000 Screenshot.png