필터 지우기
필터 지우기

What are the properties in a BoundingBox from regionprops?

조회 수: 56 (최근 30일)
Recap
Recap 2016년 3월 27일
댓글: cpaniaguam 2023년 11월 9일
I'm trying to figure out what coordinates are being stored from a BoundingBox. For instance
L=logical(bw);
box=regionprops(L,'Area', 'BoundingBox');
box(2)
And the output
ans =
Area: 127
BoundingBox: [10.5000 11.5000 10 19]
What are those 4 values? Is it the [top left, top right, bottom left, bottom right] coordinates?
  댓글 수: 2
abdelrahim hashem
abdelrahim hashem 2019년 1월 14일
Please Sir, why the values of the two components x and y is real values? Also, the last two values width and heigh are integer values?
Walter Roberson
Walter Roberson 2019년 1월 14일
There is the question of whether coordinates represent pixel centers or pixel edges.

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

채택된 답변

Image Analyst
Image Analyst 2016년 3월 27일
It's [left, top, width, height]. Just be aware that the left and top are 0.5 pixels to the left and above, respectively, than the actual first column and first row of the binary image. It's because the Bounding box is defined such that it "contains" the blob, and if it ran right through the center of the top-most and left-most pixel, then that definition becomes somewhat ambiguous.
  댓글 수: 17
Image Analyst
Image Analyst 2023년 11월 8일
@cpaniaguam the bounding box is [xLeft, yTop, width, height], and xLeft and yTop are half a pixel outside of the left most and uppermost white pixel. xLeft and yTop always end in .5 since it's outisde the blob, not on the blob, and this is just the convention they use. So if you want the actual left column and top row of the blob, you must call ceil to round them up.
And the width and height are the width and height of the bounding box, which is larger than the actual blob by half a pixel all the way around. But the width and height are of the actual blob, not the bounding box of the blob. So if you want xRight and yBottom, you must add the width-1 and height -1 to the xLeft and yTop. See this example:
img = false(5,7);
img(2:4, 3:6) = true
img = 5×7 logical array
0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0
props = regionprops(img, 'BoundingBox');
boundingBox = props.BoundingBox
boundingBox = 1×4
2.5000 1.5000 4.0000 3.0000
xMin = ceil(boundingBox(1))
xMin = 3
xMax = xMin + boundingBox(3) - 1
xMax = 6
yMin = ceil(boundingBox(2))
yMin = 2
yMax = yMin + boundingBox(4) - 1
yMax = 4
I hope that explains it better.
cpaniaguam
cpaniaguam 2023년 11월 9일
It certainly does, thanks @Image Analyst!

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

추가 답변 (2개)

elvis okacha
elvis okacha 2019년 4월 12일
편집: Walter Roberson 2019년 4월 12일
I am trying to find length and width.is this ok?:
I=Imread(filename)
Info=imfinfo(filename)
Thres=graythresh(I)
I2=~(im2bw(I,thresh))
cmp=bwconncomp(I2)
s=regionprops(cmp,'BoundingBox')
x=s.BoundingBox(3)
y=s.BoundingBox(4)
res=info.ResolutionUnit
resX=info.XResolutionUnit
resY=info.YResolutionUnit
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 4월 12일
Your image has multiple regions, so s is returning a nonscalar structure.
bb = vertcat(s.BoundingBox);
x = bb(:,1);
y = bb(:,2);
width = bb(:,3);
height = bb(:,4);
These will each be vectors, reflecting the fact that you have multiple regions.

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


SOURABH BHATTACHARYA
SOURABH BHATTACHARYA 2022년 1월 22일
편집: SOURABH BHATTACHARYA 2022년 1월 22일
The first two are the top left (x,y) coordinates while the later ones are for max width and height respectively along the respectives axes.

Community Treasure Hunt

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

Start Hunting!

Translated by