robokudo.utils.non_maxima_suppression

Non-Maxima-Suppression (NMS) implementation for object detection.

This module provides NMS implementations for filtering overlapping bounding boxes.

module:

non_maxima_suppression

synopsis:

Non-Maxima-Suppression for object detection

moduleauthor:

Lennart Heinbokel

Dependencies:

None

Created:

2023-02-02

Functions

_iou(box1, box2)

Calculate the intersection over union (IoU) of two bounding boxes.

non_max_suppression_(predictions[, ...])

Perform non-maxima suppression (NMS) on object detection results.

class_based_nms(predictions[, confidence_threshold, ...])

Perform class-based non-maximum suppression (NMS) on object detection results.

Module Contents

robokudo.utils.non_maxima_suppression._iou(box1, box2)

Calculate the intersection over union (IoU) of two bounding boxes.

Parameters:
  • box1 (tuple) – First bounding box coordinates (x1, y1, x2, y2) where: * x1, y1: coordinates of the top-left corner * x2, y2: coordinates of the bottom-right corner

  • box2 (tuple) – Second bounding box coordinates in the same format as box1

Returns:

The intersection over union value [0,1]

Return type:

float

Example:

box1 = (10, 10, 20, 20)
box2 = (15, 15, 25, 25)
iou = _iou(box1, box2)  # Returns overlap ratio
robokudo.utils.non_maxima_suppression.non_max_suppression_(predictions, confidence_treshold=0.5, iou_threshold=0.4)

Perform non-maxima suppression (NMS) on object detection results.

Parameters:
  • predictions (list) – List of tuples, where each tuple contains: * bounding box coordinates (x1, y1, x2, y2) * confidence score * class label

  • confidence_treshold (float, optional) – Minimum confidence score for a box to be considered

  • iou_threshold (float, optional) – IoU threshold above which boxes are considered to overlap

Returns:

Filtered list of predictions after applying NMS

Return type:

list

Example:

predictions = [
    ((10, 10, 20, 20), 0.9, "person"),
    ((15, 15, 25, 25), 0.8, "person")
]
filtered = non_max_suppression_(predictions)
robokudo.utils.non_maxima_suppression.class_based_nms(predictions, confidence_threshold=0.5, iou_threshold=0.4)

Perform class-based non-maximum suppression (NMS) on object detection results.

Parameters:
  • predictions (list) – List of tuples, where each tuple contains: * bounding box coordinates (x1, y1, x2, y2) * confidence score * class label

  • confidence_threshold (float, optional) – Minimum confidence score for a box to be considered

  • iou_threshold (float, optional) – IoU threshold above which boxes are considered to overlap

Returns:

Filtered list of predictions after applying class-based NMS

Return type:

list

Example:

predictions = [
    ((10, 10, 20, 20), 0.9, "person"),
    ((15, 15, 25, 25), 0.8, "car")
]
filtered = class_based_nms(predictions)

Note

This function performs NMS independently for each class, which prevents boxes of different classes from suppressing each other.