code: def draw_bbox(
      img: np.ndarray,
      bbox: BBox,
      color: Tuple[int, int, int],
      gap: bool = True,
  ):
      """Draws a box on an image with a given color.
      # Arguments
          image     : The image to draw on.
          box       : A list of 4 elements (x1, y1, x2, y2).
          color     : The color of the box.
      """
  
      # Calculate image dimensions
      dims = sorted(img.shape, reverse=True)
      color = as_rgb_tuple(color)
      img = PIL.Image.fromarray(img)
      draw = PIL.ImageDraw.Draw(img)
  
      # corner thickness is linearly correlated with the smaller image dimension.
      # We use the smaller image dimension rather than image area so as to avoid
      # overly thick lines for large non-square images prior to transforming
      # images. We set lower and upper bounds for corner thickness.
      min_corner = 1
      max_corner = 15
      corner_thickness = int(0.005 * dims[1] + min_corner)
      if corner_thickness > max_corner:
          corner_thickness = int(max_corner)
  
      corner_length = int(0.021 * dims[1] + 2.25)
  
      # inner thickness of bboxes with corners
      inner_thickness = int(1 + 0.0005 * dims[1])
  
      # bbox thickness of bboxes without corners
      min_bbox = 1
      max_bbox = 8
      bbox_thickness = int(0.0041 * dims[1] - 0.0058)
      if bbox_thickness < min_bbox:
          bbox_thickness = min_bbox
      if bbox_thickness > max_bbox:
          bbox_thickness = int(max_bbox)
  
      if gap == False:
          xyxy = tuple(np.array(bbox.xyxy, dtype=int))
          draw.rectangle(
              xyxy, fill=None, outline=color, width=bbox_thickness
          )
          return np.array(img)
  
      xmin, ymin, xmax, ymax = tuple(np.array(bbox.xyxy, dtype=int))
  
      points = [0] * 12
      points[0] = (xmin, ymin + corner_length)
      points[1] = (xmin, ymin)
      points[2] = (xmin + corner_length, ymin)
  
      points[3] = (xmax - corner_length, ymin)
      points[4] = (xmax, ymin)
      points[5] = (xmax, ymin + corner_length)
  
      points[6] = (xmax, ymax - corner_length)
      points[7] = (xmax, ymax)
      points[8] = (xmax - corner_length, ymax)
  
      points[9] = (xmin + corner_length, ymax)
      points[10] = (xmin, ymax)
      points[11] = (xmin, ymax - corner_length)
  
      if (
          ymax - (ymin + 4 * corner_length) < corner_length
          or xmax - (xmin + 4 * corner_length) < corner_length
      ):
          for i in range(4):
              draw.line(
                  xy=(points[i * 3 + 1], points[10 - 3 * i]),
                  fill=color,
                  width=bbox_thickness,
              )
          for i in range(2):
              draw.line(
                  xy=(points[6 * i + 1], points[i * 6 + 4]),
                  fill=color,
                  width=bbox_thickness,
              )
      else:
          for i in range(2):
              for j in range(2):
                  draw.line(
                      xy=(
                          points[i * 6 + j * 4],
                          points[i * 6 + j * 4 + 1],
                      ),
                      fill=color,
                      width=corner_thickness,
                      joint=None,
                  )
                  draw.line(
                      xy=(points[i * 3 + 1], points[10 - 3 * i]),
                      fill=color,
                      width=inner_thickness,
                      joint=None,
                  )
          for i in range(2):
              for j in range(2):
                  draw.line(
                      xy=(
                          points[i * 6 + j * 2 + 1],
                          points[i * 6 + j * 2 + 2],
                      ),
                      fill=color,
                      width=corner_thickness,
                      joint=None,
                  )
                  draw.line(
                      xy=(points[6 * i + 1], points[i * 6 + 4]),
                      fill=color,
                      width=inner_thickness,
                      joint=None,
                  )
  
      return np.array(img)
  
file_path: icevision/icevision/visualize/draw_data.py
imports: from icevision.imports import *
  from icevision.data import *
  from icevision.core import *
  from icevision.visualize.utils import *
  from matplotlib.colors import LinearSegmentedColormap
  from PIL import Image, ImageFont, ImageDraw
  import PIL
label_desc: Use image node_id 6 for calling a global function with example usage: draw_bbox(img, bbox, color, gap) and returns: np, np