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

2 次查看(过去 30 天)
1(110).png
  8 个评论

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2018-12-1
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 个评论
Image Analyst
Image Analyst 2018-12-2
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by