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

2 vues (au cours des 30 derniers jours)
1(110).png
  8 commentaires
Arshad Ali
Arshad Ali le 1 Déc 2018
can any one help me with the code. whats wrong with this code?
Image Analyst
Image Analyst le 1 Déc 2018
Modifié(e) : Image Analyst le 1 Déc 2018
There is no function unit8. You probably meant uint8().

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 1 Déc 2018
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
  5 commentaires
Image Analyst
Image Analyst le 2 Déc 2018
There is a function called imwrite() that you should learn of.
If you want images where there is just one blob per image, save thisBlob in the loop with imwrite() and a unique filename
filename = sprintf('Blob %d.png', k);
imwrite(thisBlob, filename);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by