Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion acvl_utils/cropping_and_padding/bounding_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ def bounding_box_to_slice(bounding_box: List[List[int]]):
return tuple([slice(*i) for i in bounding_box])


def crop_to_bbox(array: np.ndarray, bounding_box: List[List[int]]):
assert len(bounding_box) == len(array.shape), f"Dimensionality of bbox and array do not match. bbox has length " \
f"{len(bounding_box)} while array has dimension {len(array.shape)}"
slicer = bounding_box_to_slice(bounding_box)
return array[slicer]


def get_bbox_from_mask(mask: np.ndarray) -> List[List[int]]:
"""
this implementation uses less ram than the np.where one and is faster as well IF we expect the bounding box to
be close to the image size. If it's not it's likely slower!

bbox is returned so that you can just do slice(minzidx, maxzidx) to retrieve the object of interest with nothing cut off

:param mask:
Expand Down