Computer Vision

IoU & Non-Max Suppression

Evaluating spatial overlap accuracy and pruning redundant duplicate bounding boxes.

🟡 intermediate4 min readvision
Intersection over Union (IoU) measures spatial overlap between predicted bounding box A and ground-truth box B (IoU = Area of Overlap / Area of Union). Non-Maximum Suppression (NMS) is a mandatory post-processing algorithm that eliminates duplicate overlapping bounding boxes around the same object, keeping only the highest-confidence prediction. Soft-NMS decays confidence scores progressively rather than hard-deleting overlapping boxes, improving detection of crowded objects.

1. Intersection over Union (IoU)

IoU measures spatial overlap accuracy between two bounding boxes:

IoU = Area of Overlap / Area of Union = Area( A n B ) / Area( A u B )

  BOX A (Prediction) and BOX B (Ground Truth):
  ┌───────────┐
  │   Box A   │
  │     ┌─────┼──────┐          Overlap Area (A ∩ B)
  │     │ A∩B │      │  ──►   ───────────────────────  =  IoU Score ∈ [0.0, 1.0]
  └─────┼─────┘      │          Union Area (A ∪ B)
        │   Box B    │
        └────────────┘

2. Non-Maximum Suppression (NMS)

Dense object detectors predict dozens of overlapping boxes around a single physical object. NMS filters redundant candidates:

  RAW DETECTOR OUTPUT (Many Redundant Boxes):       AFTER NMS POST-PROCESSING:
       ┌──────┐ ┌──────┐ ┌──────┐                        ┌──────┐
       │ Box1 │ │ Box2 │ │ Box3 │    ──────────►         │ Box1 │ (Highest Score = 0.95)
       └──────┘ └──────┘ └──────┘                        └──────┘
       (Scores: 0.95, 0.88, 0.72)                        (Box2 & Box3 Suppressed!)

NMS Algorithm Steps

  1. Filter out all predicted boxes with confidence scores below minimum threshold (e.g. score < 0.20).
  2. Sort remaining candidate boxes by confidence score in descending order.
  3. Select box $B_{\text{max}}$ with highest score and add it to final output set.
  4. Compute IoU between $B_{\text{max}}$ and all remaining candidate boxes.
  5. Suppress (Delete) any candidate box where $\text{IoU}(B_{\text{max}}, B_i) > \text{NMS}{\text{threshold}}$ (typically $\text{NMS}{\text{threshold}} = 0.45$).
  6. Repeat steps 3–5 for remaining candidate boxes until set is empty.

Soft-NMS (Handling Crowded Scenes)

In crowded scenes (e.g. horses running side-by-side), Hard-NMS deletes real detection boxes because true objects overlap heavily.

Soft-NMS decays confidence scores continuously based on overlap rather than hard-deleting:

$$\text{Score}_i = \text{Score}i \cdot \exp\left( -\frac{\text{IoU}(B{\text{max}}, B_i)^2}{\sigma} \right)$$

Higher overlap reduces the score proportionally, allowing true secondary detections to survive if their feature evidence remains strong!

Say this out loud

IoU measures box overlap area divided by total union area. Non-Maximum Suppression (NMS) cleans up duplicate bounding box predictions around the same object by selecting the highest-confidence box and deleting surrounding candidates with high IoU overlap. Soft-NMS continuously decays confidence scores instead of hard-deleting boxes, improving detection accuracy in crowded scenes.

Follow-ups to expect

Check yourself

Question 1 of 3

What is the mathematical definition of Intersection over Union (IoU) between bounding box A and box B?

More in Computer Vision

See all →
Image Augmentation Strategies5 minResizing, Normalization & Colour Spaces4 minResNet, EfficientNet & Friends5 min