What exactly is the difference between these two pictures?
조회 수: 2 (최근 30일)
Image Analyst 2021년 9월 9일
Seems like you have not yet tried my Image Segmentation Tutorial:
Please download it, run it, and study it.
Basically your code thresholds the image to find blobs. Then it labels the blobs - each blob gets its own numerical label. But the L image is floating point. But the display functions like imshow() expect double images to be in the range 0-1 and if they are more than 1, it assumes they are one. So any blob with a label greater than 1 is going to appear white, which means the labeled image looks the same as your binary image. To get around this use  in imshow:
Now the different blobs will show up in gray scale. Here is a short version of my tutuorial:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format short g;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
grayImage = imread('eight.tif');
subplot(2, 2, 1);
% Binarize the image.
BW = ~im2bw(grayImage, 0.5);
% Fill holes.
BW = imfill(BW, 'holes');
subplot(2, 2, 2);
% Identify each blob with an ID number
L = bwlabel(BW);
subplot(2, 2, 3);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (L, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 2, 4);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(L, grayImage, 'all');
numberOfBlobs = size(blobMeasurements, 1);
title('Colorized Labeled Image');
Be sure to download the full tutorial for a complete understanding of what's going on.