code: def clip_boxes_to_image(
      boxes: NdarrayOrTensor,
      spatial_size: Sequence[int] | NdarrayOrTensor,
      remove_empty: bool = True,
  ) -> tuple[NdarrayOrTensor, NdarrayOrTensor]:
      """
      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. len(spatial_size) should be in [2, 3].
          remove_empty: whether to remove the boxes that are actually empty
  
      Returns:
          - clipped boxes, boxes[keep], does not share memory with original boxes
          - ``keep``, it indicates whether each box in ``boxes`` are kept when ``remove_empty=True``.
      """
      spatial_dims = get_spatial_dims(
          boxes=boxes, spatial_size=spatial_size
      )
      return spatial_crop_boxes(
          boxes,
          roi_start=[0] * spatial_dims,
          roi_end=spatial_size,
          remove_empty=remove_empty,
      )
  
imports: from __future__ import annotations
  import inspect
  import warnings
  from abc import ABC, abstractmethod
  from collections.abc import Callable, Sequence
  from copy import deepcopy
  import numpy
  import torch
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor
  from monai.utils import look_up_option
  from monai.utils.enums import BoxModeName
  from monai.utils.type_conversion import convert_data_type, convert_to_dst_type
label_desc: Use image node_id 16 for calling a global function with example usage: clip_boxes_to_image(boxes, spatial_size, remove_empty) and returns: spatial_crop_boxes