What is Non-Maximum Suppression?

Last Updated : 26 Jun, 2026

Non-Maximum Suppression (NMS) is a post-processing technique used in object detection to remove multiple overlapping bounding boxes that represent the same object. It retains the most confident detection, resulting in cleaner and more accurate detection results.

  • Uses confidence scores and overlap thresholds to identify the best bounding box.
  • Improves the precision and efficiency of object detection.

Types

1. Greedy NMS

Greedy Non-Maximum Suppression is the most widely used variant of NMS. It removes redundant bounding boxes by retaining the box with the highest confidence score and suppressing other boxes that significantly overlap with it.

  • Select the bounding box with the highest confidence score and compute its IoU with the remaining boxes.
  • Remove boxes whose IoU exceeds a predefined threshold.
  • Repeat the process until no boxes remain for comparison.

2. Soft NMS

Soft Non-Maximum Suppression improves upon Greedy NMS by reducing the confidence scores of overlapping bounding boxes instead of completely removing them. This helps preserve valid detections, especially in crowded scenes.

  • Select the bounding box with the highest confidence score and compute its IoU with the remaining boxes.
  • Reduce the confidence scores of overlapping boxes using a decay function rather than removing them.
  • Repeat the process and discard boxes whose updated scores fall below a threshold.

Working

step_1_input_boxes_scores_
Working of Non-Maximum Suppression
  1. Generate Bounding Boxes: The object detection model predicts multiple bounding boxes for objects in an image, along with confidence scores indicating the likelihood of each detection.
  2. Sort by Confidence Score: All predicted bounding boxes are arranged in descending order based on their confidence scores.
  3. Select the Highest-Scoring Box: The bounding box with the highest confidence score is chosen as a valid detection.
  4. Compute IoU: The Intersection over Union (IoU) between the selected box and all remaining boxes is calculated to measure their overlap.
  5. Suppress Overlapping Boxes: Bounding boxes whose IoU exceeds a predefined threshold are removed, as they are likely to represent the same object.
  6. Repeat the Process: The next highest-scoring box is selected from the remaining detections, and the IoU comparison and suppression steps are repeated until all boxes have been processed.
  7. Output Final Detections: The remaining bounding boxes are returned as the final detection results, with each box representing a unique object in the image.

Implementation

Let's consider a Python program that applies Non-Maximum Suppression (NMS) using OpenCV to remove redundant overlapping bounding boxes and retain the most confident detections.

  • Uses cv2.dnn.NMSBoxes() to perform Non-Maximum Suppression on detection results.
  • Supports configurable confidence and overlap thresholds for filtering detections.
Python
import cv2

boxes = [
    [100, 100, 120, 120],
    [110, 110, 120, 120],
    [300, 300, 100, 100]
]

scores = [0.95, 0.80, 0.90]

score_threshold = 0.5
nms_threshold = 0.4

indices = cv2.dnn.NMSBoxes(
    boxes,
    scores,
    score_threshold,
    nms_threshold
)

print("Selected Bounding Boxes:")
for i in indices:
    idx = i[0] if isinstance(i, (list, tuple)) else i
    print(boxes[idx], "Score:", scores[idx])

Output:

Selected Bounding Boxes:
[100, 100, 120, 120] Score: 0.95
[300, 300, 100, 100] Score: 0.9

Applications

  • Object Detection: Used in models such as YOLO, SSD, and Faster R-CNN to remove duplicate detections.
  • Face Detection: Helps retain a single bounding box for each detected face.
  • Autonomous Driving: Filters overlapping detections of vehicles, pedestrians, and traffic signs.

Advantages

  • Reduces Redundancy: Eliminates duplicate bounding boxes that represent the same object.
  • Improves Detection Accuracy: Retains the most confident detections while suppressing less reliable ones.
  • Enhances Efficiency: Reduces the number of bounding boxes that need further processing.

Limitations

  • Threshold Sensitivity: Detection results can vary depending on the chosen IoU threshold.
  • Missed Detections: Valid objects may be suppressed when they are located very close to each other.
  • Class-wise Processing: NMS must be applied separately for different object classes.
Comment

Explore