Bounding Box Fitting

tomni.bbox_fitting.bbox_fitting(img: numpy.ndarray, x1: int, y1: int, x2: int, y2: int, padding_value: int = 0) numpy.ndarray[source]

This function extracts a region of interest (ROI) from an input image based on a specified bounding box. It is particularly useful for isolating specific areas of interest within an image.

Parameters
  • img (-) – The input image from which the bounding box will be extracted.

  • x1 (-) – The lowest value of X-coordinate for the bounding box.

  • y1 (-) – The lowest value of Y-coordinate for the bounding box.

  • x2 (-) – The highest value of X-coordinate for the bounding box.

  • y2 (-) – The highest value of Y-coordinate for the bounding box.

  • padding_value (-) – The value assigned to pixels outside the image but within the bounding box. Defaults to 0.

Returns

The extracted image patch within the specified bounding box.

Return type

  • np.ndarray

Raises
  • - TypeError – If img is not a numpy.ndarray.

  • - ValueError – If x1, y1, x2, or y2 are not positive integers.

Note

The coordinates used in this function are in IMAGE coordinates, which follow the convention used by Pillow and OpenCV but are swapped compared to the Numpy and Scipy convention (ARRAY coordinates). Please be mindful of this difference.