Height and width of non uniform image.

1 次查看(过去 30 天)
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
Walter Roberson 2012-1-19
regionprops() ?
  1 个评论
Walter Roberson
Walter Roberson 2012-1-19
Yup. Label the image, regionprops() the labeled image, look at the bounding box.

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-1-19
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
Syahrul Niezam 2012-1-21
oh, is it mistakes there in this code?
b = uint8(a<90);% In this order!
b(a >= 110) = 180;
b(a >= 150) = 200;
b(a >= 200) = 255;
Is this code convert the image into gray-scale and rgb image? i thought it changes the image into four different regions (black, dark gray, light gray and white).
I plan to segment the infrared gray-scale image into four different regions image- (black, dark gray, light gray and white regions) using threshold before labeling them.
Is there any suggestion to do that?
Image Analyst
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
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
Syahrul Niezam 2012-1-22
I'm sorry for making you trouble.
My first question - the height and width, is the consequence from labeled images. I want to calculated the width and height of human images after segmentation (into four regions-white, light gray, dark gray and black) and labeling.
Image Analyst
Image Analyst 2012-1-22
See my BlobsDemo in my File Exchange for example/tutorial. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by