# What are the properties in a BoundingBox from regionprops?

396 views (last 30 days)
Recap on 27 Mar 2016
Edited: SOURABH BHATTACHARYA on 22 Jan 2022
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 CommentsShowHide 1 older comment
Walter Roberson on 14 Jan 2019
There is the question of whether coordinates represent pixel centers or pixel edges.

Image Analyst on 27 Mar 2016
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.
Image Analyst on 14 Dec 2018
You get BoundingBox = xLeft, yTop, width, height] so to get the coordinates you want, do
xMin = ceil(BoundingBox(1))
xMax = xMin + BoundingBox(3) - 1
yMin = ceil(BoundingBox(2))
yMax = yMin + BoundingBox(4) - 1
To flip the image upside down, use
flippedImage = flipud(originalImage);
Note though that the first line will always be the first line, it will just contain what used to be the last/bottom line of the image.

elvis okacha on 12 Apr 2019
Edited: Walter Roberson on 12 Apr 2019
I am trying to find length and width.is this ok?:
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
elvis okacha on 13 Apr 2019
Thanks

SOURABH BHATTACHARYA on 22 Jan 2022
Edited: SOURABH BHATTACHARYA on 22 Jan 2022
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.