MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / clip_boxes_to_image

Function clip_boxes_to_image

monai/data/box_utils.py:1068–1084  ·  view source on GitHub ↗

This function clips the ``boxes`` to makes sure the bounding boxes are within the image. Args: boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode`` spatial_size: The spatial size of the image where the boxes are attached.

(
    boxes: NdarrayOrTensor, spatial_size: Sequence[int] | NdarrayOrTensor, remove_empty: bool = True
)

Source from the content-addressed store, hash-verified

1066
1067
1068def clip_boxes_to_image(
1069 boxes: NdarrayOrTensor, spatial_size: Sequence[int] | NdarrayOrTensor, remove_empty: bool = True
1070) -> tuple[NdarrayOrTensor, NdarrayOrTensor]:
1071 """
1072 This function clips the ``boxes`` to makes sure the bounding boxes are within the image.
1073
1074 Args:
1075 boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``
1076 spatial_size: The spatial size of the image where the boxes are attached. len(spatial_size) should be in [2, 3].
1077 remove_empty: whether to remove the boxes that are actually empty
1078
1079 Returns:
1080 - clipped boxes, boxes[keep], does not share memory with original boxes
1081 - ``keep``, it indicates whether each box in ``boxes`` are kept when ``remove_empty=True``.
1082 """
1083 spatial_dims = get_spatial_dims(boxes=boxes, spatial_size=spatial_size)
1084 return spatial_crop_boxes(boxes, roi_start=[0] * spatial_dims, roi_end=spatial_size, remove_empty=remove_empty)
1085
1086
1087def non_max_suppression(

Callers 4

__call__Method · 0.90
test_valueMethod · 0.90

Calls 2

get_spatial_dimsFunction · 0.85
spatial_crop_boxesFunction · 0.85

Tested by 1

test_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…