Math

IoU Calculator

Compute Intersection over Union for two bounding boxes

Box A (x1, y1, x2, y2)
Box B (x1, y1, x2, y2)

IoU Calculator — Intersection over Union

Intersection over Union (IoU), also called the Jaccard index, is the standard metric for evaluating object detection models. It measures the overlap between a predicted bounding box and a ground truth bounding box. An IoU of 1.0 means perfect overlap, and 0 means no overlap at all.

How to Use This Calculator

  1. Box A — enter the four coordinates of the first bounding box as x1, y1 (top-left corner) and x2, y2 (bottom-right corner).
  2. Box B — enter the coordinates of the second bounding box in the same format.
  3. The calculator shows IoU, intersection area, union area, and individual box areas instantly.

The IoU Formula

IoU = Area of Intersection / Area of Union

Area of Union = Area(A) + Area(B) - Area of Intersection

Coordinates follow the (x1, y1, x2, y2) format where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner. This is the most common format in frameworks like PyTorch and TensorFlow.

IoU Thresholds in Object Detection

  • IoU ≥ 0.5: Standard PASCAL VOC threshold — a detection is considered correct if IoU with ground truth exceeds 0.5.
  • IoU ≥ 0.75: COCO strict threshold — used in the COCO benchmark for more precise localization.
  • IoU = 0.5 to 0.95 (COCO mAP): The COCO primary metric averages AP over IoU thresholds from 0.50 to 0.95 in steps of 0.05.
  • IoU < 0.5: Typically considered a missed detection (false negative) in standard benchmarks.

Applications of IoU

Object detection evaluation: YOLO, Faster R-CNN, SSD, and other detectors use IoU to determine whether a predicted box matches a ground truth box.

Non-maximum suppression (NMS): During inference, IoU is used to eliminate duplicate detections — if two boxes have IoU above a threshold, only the one with the higher confidence score is kept.

Segmentation evaluation: IoU is applied to binary masks (pixel sets) in semantic and instance segmentation, where intersection and union are computed over pixel sets instead of rectangles.

Anchor box design: When designing anchor boxes for anchor-based detectors, IoU is used to select scales and aspect ratios that maximize overlap with ground truth boxes in the training set.

Frequently Asked Questions

What is a good IoU score for object detection?
The standard threshold is 0.5 (used by PASCAL VOC). COCO uses 0.75 for strict matching and averages IoU from 0.5 to 0.95. In practice, IoU above 0.5 is considered a correct detection, and models targeting high precision aim for 0.75 or higher.
What coordinate format does this calculator use?
This calculator uses the (x1, y1, x2, y2) format where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner. x2 must be greater than x1, and y2 must be greater than y1. Pixel or normalized coordinates both work.
What does IoU = 0 mean?
IoU of 0 means the two bounding boxes do not overlap at all — their intersection area is zero. In object detection, this means the predicted box completely missed the ground truth object.
Is IoU the same as the Jaccard index?
Yes. IoU is mathematically identical to the Jaccard similarity coefficient. The Jaccard index is a general set similarity measure defined as |A ∩ B| / |A ∪ B|. When applied to bounding boxes, it becomes Intersection over Union.
Can IoU be used for rotated bounding boxes?
Standard IoU assumes axis-aligned rectangles. For rotated bounding boxes, the computation requires polygon intersection which is more complex. Frameworks like Detectron2 offer rotated IoU functions for oriented object detection.
What is GIoU and DIoU?
GIoU (Generalized IoU) and DIoU (Distance IoU) are loss function variants that address gradient issues when boxes do not overlap. GIoU penalizes the enclosing box area, while DIoU also considers the center distance. These are used as regression losses, not evaluation metrics.