필터 지우기
필터 지우기

Union of two bounding boxes

조회 수: 1 (최근 30일)
FARHAD
FARHAD 2014년 5월 22일
댓글: Image Analyst 2014년 5월 24일
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)];

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 22일
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
FARHAD
FARHAD 2014년 5월 22일
편집: FARHAD 2014년 5월 23일
Thanks a lot. Could you explain me the following line of the previous one. Why they have added 1(one) here? unionArea=(unionCoords(3)-unionCoords(1)+1)*(unionCoords(4)-unionCoords(2)+1);
Image Analyst
Image Analyst 2014년 5월 24일
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.

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

Community Treasure Hunt

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

Start Hunting!

Translated by