What exactly is the difference between these two pictures?

조회 수: 2 (최근 30일)
Andrew Killian
Andrew Killian . 2021년 9월 9일
댓글: Image Analyst . 2021년 9월 10일
When I compare the two figures side by side they look exactly the same to me.
guitar = imread('guitar.jpg');
BW = im2bw(guitar, 0.5);
L = bwlabel(BW);
figure(1); imshow(L);
figure(2); imshow(BW);

답변 (1개)

Image Analyst
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:
imshow(:, []);
Now the different blobs will show up in gray scale. Here is a short version of my tutuorial:
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
grayImage = imread('eight.tif');
subplot(2, 2, 1);
title('Original Image');
% Binarize the image.
BW = ~im2bw(grayImage, 0.5);
% Fill holes.
BW = imfill(BW, 'holes');
subplot(2, 2, 2);
title('Binary Image');
% Identify each blob with an ID number
L = bwlabel(BW);
subplot(2, 2, 3);
imshow(L, []);
title('Labeled Image');
% 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.
  댓글 수: 2
Image Analyst
Image Analyst 2021년 9월 10일
@Andrew Killian hang in there. Most of image processing comes down to simply thresholding. You start with an image, then do stuff to it where you can get down to an image that you can threshold into foreground and background. Then you call regionprops to measure things about the image. The simplest image processing program can be done in only 3 lines of code:
grayImage = imread(fileName);
binaryImage = imbinarize(grayImage); % Threshold and form a binary image.
props = regionprops(binaryImage); % Measure a bunch of things about the binary blobs.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by