TensorTonic
Problems
Intersection over Union (IoU)
Computer VisionMetrics & Evaluation
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
Anchor Box GenerationMediumNon-Maximum SuppressionMediumROI PoolingHardCompute AUC (Area Under ROC)EasyImplement Micro-F1EasyImplement Precision and Recall at K in PythonEasyColor to GrayscaleEasyCatalog CoverageEasyPairwise IoUEasyGeneralized IoU LossMediumComplete IoU LossMediumTop-K Classification AccuracyEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Intersection over Union (IoU)

Intersection over Union (IoU)

Computer VisionMetrics & Evaluation
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
Anchor Box GenerationMediumNon-Maximum SuppressionMediumROI PoolingHardCompute AUC (Area Under ROC)EasyImplement Micro-F1EasyImplement Precision and Recall at K in PythonEasyColor to GrayscaleEasyCatalog CoverageEasyPairwise IoUEasyGeneralized IoU LossMediumComplete IoU LossMediumTop-K Classification AccuracyEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1