What exactly is the difference between these two pictures?

1 回表示 (過去 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);
imshow(grayImage);
title('Original Image');
% Binarize the image.
BW = ~im2bw(grayImage, 0.5);
% Fill holes.
BW = imfill(BW, 'holes');
subplot(2, 2, 2);
imshow(BW);
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);
imshow(coloredLabelsImage);
% 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 件のコメント
Andrew Killian
Andrew Killian 2021 年 9 月 9 日
編集済み: Andrew Killian 2021 年 9 月 9 日
Ok thanks. It would probably help if I had a specific thing I don't understand. But for a majority of this computer vision stuff I feel like I don't know what I don't know. This makes it extremely frustrating.
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by