detection_reassembly module

This module defines functions for reassembling tiled detections.

utilities.detection_reassembly.compute_area(box: Tuple[float, float, float, float])

Computes the area of a rectangle.

Parameters:

box (Tuple[float, float, float, float]) – A tuple of four floats that define the (left, top, right, bottom) of a rectangle.

Returns:

The area of the rectangle.

utilities.detection_reassembly.compute_intersection_area(box_1: Tuple[float, float, float, float], box_2: Tuple[float, float, float, float]) float

Computes the area of the intersection of two rectangle.

Parameters:
  • box_1 (Tuple[float, float, float, float]) – A tuple of four floats that define the (left, top, right, bottom) of the first rectangle.

  • box_2 (Tuple[float, float, float, float]) – A tuple of four floats that define the (left, top, right, bottom) of the second rectangle.

Returns:

The area of the intersection of the two rectangles box_1 and box_2.

utilities.detection_reassembly.intersection_over_minimum(detection_1: Detection, detection_2: Detection) float

Calculates the Intersection over Minimum (IoM) between two detections.

This function calculates the area of overlap between the two bounding boxes of two detection objects and divides it by the area of the smaller detection.

Parameters:
  • detection_1 (Detection) – A Detection object representing the first detection.

  • detection_2 (Detection) – A Detection object representing the second detection.

Returns:

A float value between 0.0 and 1.0 representing the IoM between the two detections.

utilities.detection_reassembly.intersection_over_union(detection_1: Detection, detection_2: Detection) float

Calculates the Intersection over Union (IoU) between two detections.

This function calculates the area of overlap between the bounding boxes of two detection objects and divides it by the total area covered by their bounding boxes.

Parameters:
  • detection_1 (Detection) – A Detection object representing the first detection.

  • detection_2 (Detection) – A Detection object representing the second detection.

Returns:

A float value between 0.0 and 1.0 representing the IoU between the two detections.

utilities.detection_reassembly.non_maximum_suppression(detections: ~typing.List[~utilities.detections.Detection], threshold: float = 0.5, overlap_comparator: ~typing.Callable[[~utilities.detections.Detection, ~utilities.detections.Detection], float] = <function intersection_over_union>) List[Detection]

Applies Non-Maximum Suppression (NMS) to a list of detections.

This function filters a list of detections to remove overlapping bounding boxes based on their confidence scores. It keeps only the detections with the highest confidence scores for each object.

Parameters:
  • detections (List[Detection]) – A list of Detection objects representing the detections to be filtered.

  • threshold (float) – A float value between 0.0 and 1.0, representing the minimum IoU (Intersection over Union) threshold for discarding detections considered to overlap with a higher-confidence detection. (default: 0.5)

  • overlap_comparator – A callable function that takes two Detection objects as arguments and returns a float value representing the IoU (overlap) between their bounding boxes. (default: intersection_over_union function)

Returns:

A list of Detection objects containing the filtered detections after applying NMS.

utilities.detection_reassembly.untile_detections(tiled_detections: List[List[List[Detection]]], tile_width: int, tile_height: int, horizontal_overlap_ratio: float, vertical_overlap_ratio: float) List[Detection]

Squashes multiple detection lists into one and corrects their location on the main image.

Parameters:
  • tiled_detections (List[List[Detection]]) – A list of detections made on tiles.

  • slice_height (int) – The height of each slice.

  • slice_width (int) – The width of each slice.

  • horizontal_overlap_ratio (float) – The amount of left-right overlap between slices.

  • vertical_overlap_ratio (float) – The amount of top-bottom overlap between slices.