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일)
이전 댓글 표시
댓글 수: 8
Image Analyst
2018년 12월 1일
편집: Image Analyst
2018년 12월 1일
There is no function unit8. You probably meant uint8().
채택된 답변
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
댓글 수: 5
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 Center 및 File 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!