TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Intersection over Union (IoU)

Metrics & EvaluationComputer Vision
Easy

Compute Intersection over Union for two axis-aligned boxes. Each box is given as [x1,y1,x2,y2][x_1,y_1,x_2,y_2][x1​,y1​,x2​,y2​], where the first point is the top-left corner and the second is the bottom-right corner.

Aintersection=max⁡(0,xR−xL)max⁡(0,yB−yT)A_{\mathrm{intersection}}=\max(0,x_R-x_L)\max(0,y_B-y_T)Aintersection​=max(0,xR​−xL​)max(0,yB​−yT​) Aunion=AA+AB−AintersectionA_{\mathrm{union}}=A_A+A_B-A_{\mathrm{intersection}}Aunion​=AA​+AB​−Aintersection​ IoU⁡=AintersectionAunion\operatorname{IoU}=\frac{A_{\mathrm{intersection}}}{A_{\mathrm{union}}}IoU=Aunion​Aintersection​​

Here, xLx_LxL​ and yTy_TyT​ are the largest starting coordinates, while xRx_RxR​ and yBy_ByB​ are the smallest ending coordinates. Return zero when the union is zero. Otherwise return IoU as a Python float.

Loading visualization...

Examples

Input: box_a = [0, 0, 4, 4], box_b = [2, 2, 6, 6]

Output: 0.142857

Explanation: The intersection area is 4 and the union area is 28.

Input: box_a = [0, 0, 2, 2], box_b = [3, 3, 5, 5]

Output: 0

Hint 1

Use maximum starting coordinates and minimum ending coordinates for the intersection.

Hint 2

Compute union with area_a + area_b - intersection.

Requirements

  • Compute the overlapping width and height without allowing negative values
  • Compute both box areas and their union
  • Return zero for a zero-area union
  • Return IoU as a float

Constraints

  • Each box contains four numeric coordinates
  • The ending coordinate is not smaller than the corresponding starting coordinate
Try Similar Problems
Metrics F1 MicroAucNon Maximum SuppressionAnchor Box GenerationRoi Pooling

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Intersection over Union (IoU)

Metrics & EvaluationComputer Vision
Easy

Compute Intersection over Union for two axis-aligned boxes. Each box is given as [x1,y1,x2,y2][x_1,y_1,x_2,y_2][x1​,y1​,x2​,y2​], where the first point is the top-left corner and the second is the bottom-right corner.

Aintersection=max⁡(0,xR−xL)max⁡(0,yB−yT)A_{\mathrm{intersection}}=\max(0,x_R-x_L)\max(0,y_B-y_T)Aintersection​=max(0,xR​−xL​)max(0,yB​−yT​) Aunion=AA+AB−AintersectionA_{\mathrm{union}}=A_A+A_B-A_{\mathrm{intersection}}Aunion​=AA​+AB​−Aintersection​ IoU⁡=AintersectionAunion\operatorname{IoU}=\frac{A_{\mathrm{intersection}}}{A_{\mathrm{union}}}IoU=Aunion​Aintersection​​

Here, xLx_LxL​ and yTy_TyT​ are the largest starting coordinates, while xRx_RxR​ and yBy_ByB​ are the smallest ending coordinates. Return zero when the union is zero. Otherwise return IoU as a Python float.

Loading visualization...

Examples

Input: box_a = [0, 0, 4, 4], box_b = [2, 2, 6, 6]

Output: 0.142857

Explanation: The intersection area is 4 and the union area is 28.

Input: box_a = [0, 0, 2, 2], box_b = [3, 3, 5, 5]

Output: 0

Hint 1

Use maximum starting coordinates and minimum ending coordinates for the intersection.

Hint 2

Compute union with area_a + area_b - intersection.

Requirements

  • Compute the overlapping width and height without allowing negative values
  • Compute both box areas and their union
  • Return zero for a zero-area union
  • Return IoU as a float

Constraints

  • Each box contains four numeric coordinates
  • The ending coordinate is not smaller than the corresponding starting coordinate
Try Similar Problems
Metrics F1 MicroAucNon Maximum SuppressionAnchor Box GenerationRoi Pooling

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.