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
)
| 1066 | |
| 1067 | |
| 1068 | def 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 | |
| 1087 | def non_max_suppression( |
searching dependent graphs…