code: def draw_segmentation_mask(
      img: np.ndarray,
      mask: MaskArray,
      cmap: LinearSegmentedColormap,
      display_mask: bool = True,
      alpha: float = 0.5,
  ):
      img = PIL.Image.fromarray(img).convert("RGB")
  
      if display_mask:
          w, h = img.size
          mask_arr = np.zeros((h, w, 3), dtype=np.uint8)
          mask = mask.data.squeeze()
  
          assert mask.shape == (h, w), (
              "image and mask size should be the same"
              f"but got image:{(w, h)}; mask: {(mask.shape[::-1])}"
          )
  
          for class_idx in np.unique(mask):
              mask_idxs = mask == class_idx
              mask_arr[mask_idxs] = np.array(cmap(class_idx)[:3]) * 255
  
          mask_pil = PIL.Image.fromarray(mask_arr)
          img = PIL.Image.blend(img, mask_pil, alpha=alpha)
  
      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 8 for calling a global function with example usage: draw_segmentation_mask(img, mask, cmap, display_mask, alpha) and returns: np