mask2bbox

tomni.transformers.mask2bbox(mask: numpy.ndarray, padding: int = 0) tuple[source]

Convert a binary image mask into bounding box coordinates (xmin, ymin, xmax, ymax).

Parameters
  • mask (np.ndarray) – A binary image mask represented as a NumPy array where 1 indicates the object of interest, and 0 indicates the background.

  • padding (int, optional) – Padding added or subtracted from the bounding box coordinates. The resulting bounding box coordinates will not exceed the image dimensions. If padding is positive, it adds padding to all sides of the bounding box; if negative, it subtracts padding. Defaults to 0.

Returns

A tuple containing the bounding box coordinates (xmin, ymin, xmax, ymax).

The coordinates represent the top-left and bottom-right corners of the bounding box.

Return type

tuple