Calculate each object maximum height and weight

How can I calculate each object maximum height and weight in the following example?
I used this code:
clc;
clear;
I = rgb2gray(imread('http://i67.tinypic.com/14jxq0y.jpg'));
adpt1 = imbinarize(I);
adpt1 = imfill(adpt1, 'holes');
[B,L] = bwboundaries(adpt1,'noholes');
stat = regionprops(adpt1,'All');
imshow(adpt1);
hold on
for k = 1 : length(B)
b = B{k};
c = stat(k).Centroid;
plot(b(:,2),b(:,1),'g','linewidth',3);
text(c(1),c(2),num2str(k),'backgroundcolor','g');
end

댓글 수: 1

You have curved objects.
For "height" are you looking for the height of the highest point minus the height of the lowest point?
Are you looking to do the equivalent of running a ruler horizontally along the figure and examine the maximum point minus the minimum point at each column, and find the largest difference amongst those -- the "thickest" vertical?
In your object #4, top center, the left side is concave, so if you did that you would have a gap along the vertical line: is only the solid part to be counted, or the furthest reaches?
Are you looking to find the maximum axes and the axes 90 degrees to that? For example in object #6, right center, the maximum axis is along the diagonal from top left to bottom right: is that one of the distances to be measured, and then the other would be the diagonal from bottom left to top right?

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

 채택된 답변

Image Analyst
Image Analyst 2017년 2월 2일

1 개 추천

Ask regionprops to return the Bounding Box.
In the loop
thisBB = stats(k).BoundingBox
thisWidth = thisBB(3);
thisHeight = thisBB(4);
hold on;
rectangle('Position', thisBB, 'EdgeColor', 'c');

댓글 수: 6

How can I access the Bounding Box information for every object in the loop and print it out (Output line: "object k, width is VALUE, height is VALUE")? (The Bounding Box struct contain 4 numbers which I do not know what they mean and how to extract them out)
Code:
clc;
clear;
I = rgb2gray(imread('http://i67.tinypic.com/14jxq0y.jpg'));
adpt1 = imbinarize(I);
adpt1 = imfill(adpt1, 'holes');
[B,L] = bwboundaries(adpt1,'noholes');
stat = regionprops(adpt1,'All');
imshow(I);
hold on
for k = 1 : length(B)
b = B{k};
c = stat(k).Centroid;
plot(b(:,2),b(:,1),'g','linewidth',3);
text(c(1),c(2),num2str(k),'backgroundcolor','g');
rectangle('Position', stat(k).BoundingBox,'EdgeColor', 'c');
end
"The Bounding Box struct contain 4 numbers which I do not know what they mean"
That's easily solved by looking it up in the documentation.
The four values are: [x_upperleftcorner, y_upperleftcorner, width, height]
Now what the regionprops documentation does not explain or link to is what x and y mean in a coordinate system that uses rows and columns!
Ely Raz
Ely Raz 2017년 2월 3일
How can I extract the width, height to 2 different variables from the stat(k).BoundingBox?
I already showed you that:
thisWidth = thisBB(3);
thisHeight = thisBB(4);
Walter Roberson
Walter Roberson 2017년 2월 4일
편집: Walter Roberson 2017년 2월 4일
Hee. I see you've started using my naming practice of " this such and such" ;-)
I think I picked that up in 2003 when I learned Java. I thought it was a good idea so I use it occasionally.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2017년 2월 2일

댓글:

2017년 2월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by