Union of two bounding boxes
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have two bounding boxes xg and pr and I want to know why we subtract 1 from width_g in the following code to calculate the union coordinates of two bounding boxes.
unionCoords=[min(x_g,x_p),min(y_g,y_p),max(x_g+width_g-1,x_p+width_p-1),max(y_g+height_g-1,y_p+height_p-1)];
0 Kommentare
Antworten (1)
Image Analyst
am 22 Mai 2014
That's not the union of two bounding boxes. That's the bounding box of the two bounding boxes. There is a difference.
They have a bounding box with values of top, left, width, and height and those are in units of pixels, not center to center. So if the left is at 11 and the width is 4, they consider it going not from 11 to 15 but from 11 to 14, in other words pixels # 11, 12, 13, and 14 (4 pixels). So that's why they subtract 1.
2 Kommentare
Image Analyst
am 24 Mai 2014
That's because they want to use whole pixels in calculating the area instead of going from center to center. Look at the square below:
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 1 1 1 1 0
0 0 0 0 0 0 0
What is the width of that square? Is it 3 wide (going from center to center of each pixel), or is it 4 (includes the whole pixel). So is the area 9 or 16? Neither is necessarily right or wrong, and I use both definitions at different times depending on what I want to do. bwarea() will give you a center-to-center area while regionprops() will give you the area in whole pixels.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!