Intersection over Union is the standard metric for measuring how well a predicted bounding box overlaps with a ground truth box. It is used everywhere in object detection to evaluate predictions and to filter duplicates.
Given two axis-aligned bounding boxes, each represented as [x1, y1, x2, y2] where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner, compute their IoU.
If both boxes have zero area (and thus union is zero), return 0.0.
Return the IoU as a float in the range [0, 1].
Input:
box_a = [0, 0, 4, 4] box_b = [2, 2, 6, 6]
Output:
0.142857...
The boxes overlap in a 2x2 region (area 4). Each box has area 16, so union = 16 + 16 - 4 = 28. IoU = 4/28.
Input:
box_a = [0, 0, 2, 2] box_b = [3, 3, 5, 5]
Output:
0.0
The boxes do not overlap at all. Intersection area is zero.
The intersection rectangle's corners can be found using max/min of the input corners. Make sure the width and height cannot be negative.
Union is not just the sum of both areas. You need to subtract the intersection to avoid double-counting.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Intersection over Union is the standard metric for measuring how well a predicted bounding box overlaps with a ground truth box. It is used everywhere in object detection to evaluate predictions and to filter duplicates.
Given two axis-aligned bounding boxes, each represented as [x1, y1, x2, y2] where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner, compute their IoU.
If both boxes have zero area (and thus union is zero), return 0.0.
Return the IoU as a float in the range [0, 1].
Input:
box_a = [0, 0, 4, 4] box_b = [2, 2, 6, 6]
Output:
0.142857...
The boxes overlap in a 2x2 region (area 4). Each box has area 16, so union = 16 + 16 - 4 = 28. IoU = 4/28.
Input:
box_a = [0, 0, 2, 2] box_b = [3, 3, 5, 5]
Output:
0.0
The boxes do not overlap at all. Intersection area is zero.
The intersection rectangle's corners can be found using max/min of the input corners. Make sure the width and height cannot be negative.
Union is not just the sum of both areas. You need to subtract the intersection to avoid double-counting.
Sign in to take notes on this problem
Accepts: array
Accepts: array