Height and width of non uniform image.
이전 댓글 표시
Is there any idea how to calculate height and width of region of image? I want to measure the height and width of selected region as shown in this image.
답변 (3개)
Walter Roberson
2012년 1월 19일
0 개 추천
regionprops() ?
댓글 수: 1
Walter Roberson
2012년 1월 19일
Yup. Label the image, regionprops() the labeled image, look at the bounding box.
Image Analyst
2012년 1월 19일
0 개 추천
Images have to be rectangular. For the image
[rows columns numberOfColorChannels] = size(imageArray);
For the region within the image, you need to do as Walter says, get a binary image, call bwlabel, then call regionprops. See BlobsDemo http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 if you need an image segmentation tutorial/demo.
댓글 수: 14
Syahrul Niezam
2012년 1월 19일
Walter Roberson
2012년 1월 19일
Yes. regionprops() does not care how you generate the labeled matrix, only that it receives a labeled matrix. And at a pinch, even a binary matrix qualifies as a labeled matrix: everywhere set to 1 binary would be considered to be part of the same region.
David Young
2012년 1월 19일
Not exactly. If the matrix is of class double, and is binary in the sense of containing only values 0 and 1, then yes, everywhere set to 1 is part of the same (possibly disconnected) region.
However, if the matrix is of class logical, then regionprops treats each connected region of 1s as separate, as if bwlabel(bw) had been passed instead of bw.
Walter Roberson
2012년 1월 19일
Creeping Featuritis! ;-)
Image Analyst
2012년 1월 19일
Yeah, I noticed that a couple of versions ago. If you have a binary image (say from thresholding) you can pass it right in to regionprops() without using bwlabel. I still use bwlabel though - force of habit I guess, or just to be super explicit. I think now though it actually probably passes the binary image to bwconncomp() since it seems like they're trying to promote that as the replacement for bwlabel().
Syahrul Niezam
2012년 1월 19일
Walter Roberson
2012년 1월 19일
What output do you get from segmenting? How can you tell the different segments apart?
Image Analyst
2012년 1월 20일
The threshold method DOES give a binary image:
binaryImage = grayImage < thresholdValue;
% binaryImage is a logical image.
Syahrul Niezam
2012년 1월 20일
Image Analyst
2012년 1월 20일
So is it working now?
Syahrul Niezam
2012년 1월 20일
Image Analyst
2012년 1월 21일
I don't see the 4 regions. I see (1) white background, (2) gray blob, (3) red blob, (4) arrow #1, and (5) arrow #2. Which regions do you want to measure?
Syahrul Niezam
2012년 1월 21일
Image Analyst
2012년 1월 22일
Just use 1,2,3 instead of 180, 200, and 255 and you'll have a labeled image. a and b must be gray scale images.
Image Analyst
2012년 1월 21일
Try it like this instead:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
rgbImage = imread('C:\Users\Syahrul\Documents\Temporary\szuzpc.jpg');
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(2, 3, 2);
imshow(redChannel, []);
title('Red Channel Image', 'FontSize', fontSize);
subplot(2, 3, 3);
imshow(greenChannel, []);
title('Green Channel Image', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(blueChannel, []);
title('Blue Channel Image', 'FontSize', fontSize);
% Combine channels to get just the red blob only.
redBlob = blueChannel <= 50 & redChannel > 50;
% Get rid of blobs less than 1000 in pixel area.
redBlob = bwareaopen(redBlob, 1000);
subplot(2, 3, 5);
imshow(redBlob, []);
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(redBlob, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
axis on;
title('Red Blob Alone', 'FontSize', fontSize);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'area', 'BoundingBox');
numberOfBlobs = size(blobMeasurements, 1);
area = [blobMeasurements.Area] % Vector of all areas (should only be 1).
% Get the bounding box.
bb = [blobMeasurements.BoundingBox] % Vector of all areas (should only be 1).
x1 = bb(1)
x2 = x1 + bb(3)
y1 = bb(2)
y2 = y1 + bb(4)
% Plot red blob with box around it.
subplot(2, 3, 6);
imshow(coloredLabelsImage, []);
axis on;
title('Red Blob With Bounding Box', 'FontSize', fontSize);
hold on;
plot([x1 x2 x2 x1 x1], [y1 y1 y2 y2 y1], 'y-', 'LineWidth', 2);
% Display message
message = sprintf('Done with demo!\nWidth = %f\nHeight = %f', bb(3), bb(4));
msgbox(message);
댓글 수: 5
Syahrul Niezam
2012년 1월 21일
Syahrul Niezam
2012년 1월 21일
Image Analyst
2012년 1월 22일
Um,these images are TOTALLY different than the computer graphics image you gave us first. These are thermal grayscale images of a real outdoor scene. So of course the code I wasted my time on for your computer graphics image won't work for this image. Good luck with this.
Syahrul Niezam
2012년 1월 22일
Image Analyst
2012년 1월 22일
See my BlobsDemo in my File Exchange for example/tutorial. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
카테고리
도움말 센터 및 File Exchange에서 Blue에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!