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

Function centers_in_boxes

monai/data/box_utils.py:649–677  ·  view source on GitHub ↗

Checks which center points are within boxes Args: boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``. centers: center points, Nx2 or Nx3 torch tensor or ndarray. eps: minimum distance to border of boxes. Re

(centers: NdarrayOrTensor, boxes: NdarrayOrTensor, eps: float = 0.01)

Source from the content-addressed store, hash-verified

647
648
649def centers_in_boxes(centers: NdarrayOrTensor, boxes: NdarrayOrTensor, eps: float = 0.01) -> NdarrayOrTensor:
650 """
651 Checks which center points are within boxes
652
653 Args:
654 boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``.
655 centers: center points, Nx2 or Nx3 torch tensor or ndarray.
656 eps: minimum distance to border of boxes.
657
658 Returns:
659 boolean array indicating which center points are within the boxes, sized (N,).
660
661 Reference:
662 https://github.com/MIC-DKFZ/nnDetection/blob/main/nndet/core/boxes/ops.py
663
664 """
665 spatial_dims = get_spatial_dims(boxes=boxes)
666
667 # compute relative position of centers compared to borders
668 # should be non-negative if centers are within boxes
669 center_to_border = [centers[:, axis] - boxes[:, axis] for axis in range(spatial_dims)] + [
670 boxes[:, axis + spatial_dims] - centers[:, axis] for axis in range(spatial_dims)
671 ]
672
673 if isinstance(boxes, np.ndarray):
674 min_center_to_border: np.ndarray = np.stack(center_to_border, axis=1).min(axis=1)
675 return min_center_to_border > eps # array[bool]
676
677 return torch.stack(center_to_border, dim=1).to(COMPUTE_DTYPE).min(dim=1)[0] > eps # type: ignore
678
679
680def boxes_center_distance(

Callers 2

compute_matchesMethod · 0.90
test_valueMethod · 0.90

Calls 1

get_spatial_dimsFunction · 0.85

Tested by 1

test_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…