code: def convert_box_to_mask(
      boxes: NdarrayOrTensor,
      labels: NdarrayOrTensor,
      spatial_size: Sequence[int] | int,
      bg_label: int = -1,
      ellipse_mask: bool = False,
  ) -> NdarrayOrTensor:
      """
      Convert box to int16 mask image, which has the same size with the input image.
  
      Args:
          boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``.
          labels: classification foreground(fg) labels corresponding to `boxes`, dtype should be int, sized (N,).
          spatial_size: image spatial size.
          bg_label: background labels for the output mask image, make sure it is smaller than any fg labels.
          ellipse_mask: bool.
  
              - If True, it assumes the object shape is close to ellipse or ellipsoid.
              - If False, it assumes the object shape is close to rectangle or cube and well occupies the bounding box.
              - If the users are going to apply random rotation as data augmentation, we suggest setting ellipse_mask=True
                See also Kalra et al. "Towards Rotation Invariance in Object Detection", ICCV 2021.
  
      Return:
          - int16 array, sized (num_box, H, W). Each channel represents a box.
              The foreground region in channel c has intensity of labels[c].
              The background intensity is bg_label.
      """
      spatial_dims: int = get_spatial_dims(boxes=boxes)
      spatial_size = ensure_tuple_rep(spatial_size, spatial_dims)
  
      # if no box, return empty mask
      if labels.shape[0] == 0:
          boxes_mask_np = np.ones(
              (1,) + spatial_size, dtype=np.int16
          ) * np.int16(bg_label)
          boxes_mask, *_ = convert_to_dst_type(
              src=boxes_mask_np, dst=boxes, dtype=torch.int16
          )
          return boxes_mask
  
      # bg_label should be smaller than labels
      if bg_label >= min(labels):
          raise ValueError(
              f"bg_label should be smaller than any foreground box labels.\n"
              f"min(labels)={min(labels)}, while bg_label={bg_label}"
          )
  
      if labels.shape[0] != boxes.shape[0]:
          raise ValueError(
              "Number of labels should equal to number of boxes."
          )
  
      # allocate memory for boxes_mask_np
      boxes_mask_np = np.ones(
          (labels.shape[0],) + spatial_size, dtype=np.int16
      ) * np.int16(bg_label)
  
      boxes_np: np.ndarray = convert_data_type(
          boxes, np.ndarray, dtype=np.int32
      )[0]
      if np.any(boxes_np[:, spatial_dims:] > np.array(spatial_size)):
          raise ValueError("Some boxes are larger than the image.")
  
      labels_np, *_ = convert_to_dst_type(src=labels, dst=boxes_np)
      for b in range(boxes_np.shape[0]):
          # generate a foreground mask
          box_size = [
              boxes_np[b, axis + spatial_dims] - boxes_np[b, axis]
              for axis in range(spatial_dims)
          ]
          if ellipse_mask:
              # initialize a square/cube mask
              max_box_size = max(box_size)  # max of box w/h/d
              radius = max_box_size / 2.0
              center = (max_box_size - 1) / 2.0
              boxes_only_mask = np.ones(
                  [max_box_size] * spatial_dims, dtype=np.int16
              ) * np.int16(bg_label)
              # apply label intensity to generate circle/ball foreground
              ranges = tuple(
                  slice(0, max_box_size) for _ in range(spatial_dims)
              )
              dist_from_center = sum(
                  (grid - center) ** 2 for grid in np.ogrid[ranges]
              )
              boxes_only_mask[
                  dist_from_center <= radius**2
              ] = np.int16(labels_np[b])
              # squeeze it to a ellipse/ellipsoid mask
              resizer = Resize(
                  spatial_size=box_size,
                  mode="nearest",
                  anti_aliasing=False,
              )
              boxes_only_mask = resizer(boxes_only_mask[None])[0]  # type: ignore
          else:
              # generate a rect mask
              boxes_only_mask = np.ones(
                  box_size, dtype=np.int16
              ) * np.int16(labels_np[b])
          # apply to global mask
          slicing = [b]
          slicing.extend(
              slice(boxes_np[b, d], boxes_np[b, d + spatial_dims])
              for d in range(spatial_dims)
          )  # type:ignore
          boxes_mask_np[tuple(slicing)] = boxes_only_mask
      return convert_to_dst_type(
          src=boxes_mask_np, dst=boxes, dtype=torch.int16
      )[0]
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from copy import deepcopy
  import numpy
  import torch
  from monai.config.type_definitions import DtypeLike, NdarrayOrTensor, NdarrayTensor
  from monai.data.box_utils import COMPUTE_DTYPE, TO_REMOVE, get_spatial_dims
  from monai.transforms import Resize
  from monai.transforms.utils import create_scale
  from monai.utils import look_up_option
  from monai.utils.misc import ensure_tuple, ensure_tuple_rep
  from monai.utils.type_conversion import convert_data_type, convert_to_dst_type
label_desc: Use image node_id 6 for calling a global function with example usage: convert_box_to_mask(boxes, labels, spatial_size, bg_label, ellipse_mask) and returns: convert_to_dst_type, boxes_mask