class_docstr: Visualizer that draws data about detection/segmentation on images.
  
  It contains methods like `draw_{text,box,circle,line,binary_mask,polygon}`
  that draw primitive objects to images, as well as high-level wrappers like
  `draw_{instance_predictions,sem_seg,panoptic_seg_predictions,dataset_dict}`
  that draw composite data in some pre-defined style.
  
  Note that the exact visualization style for the high-level wrappers are subject to change.
  Style such as color, opacity, label contents, visibility of labels, or even the visibility
  of objects themselves (e.g. when the object is too small) may change according
  to different heuristics, as long as the results still look visually reasonable.
  
  To obtain a consistent style, you can implement custom drawing functions with the
  abovementioned primitive methods instead. If you need more customized visualization
  styles, you can process the data yourself following their format documented in
  tutorials (:doc:`/tutorials/models`, :doc:`/tutorials/datasets`). This class does not
  intend to satisfy everyone's preference on drawing styles.
  
  This visualizer focuses on high rendering quality rather than performance. It is not
  designed to be used for real-time applications.
class_docstr_tok: ["Visualizer","that","draws","data","about","detection\/segmentation","on","images",".","It","contains","methods","like","`","draw_","{","text",",","box",",","circle",",","line",",","binary_mask",",","polygon","}","`","that","draw","primitive","objects","to","images",",","as","well","as","high-level","wrappers","like","`","draw_","{","instance_predictions",",","sem_seg",",","panoptic_seg_predictions",",","dataset_dict","}","`","that","draw","composite","data","in","some","pre-defined","style",".","Note","that","the","exact","visualization","style","for","the","high-level","wrappers","are","subject","to","change",".","Style","such","as","color",",","opacity",",","label","contents",",","visibility","of","labels",",","or","even","the","visibility","of","objects","themselves","(","e.g",".","when","the","object","is","too","small",")","may","change","according","to","different","heuristics",",","as","long","as","the","results","still","look","visually","reasonable",".","To","obtain","a","consistent","style",",","you","can","implement","custom","drawing","functions","with","the","abovementioned","primitive","methods","instead",".","If","you","need","more","customized","visualization","styles",",","you","can","process","the","data","yourself","following","their","format","documented","in","tutorials","(",":","doc",":","`","\/tutorials\/models","`",",",":","doc",":","`","\/tutorials\/datasets","`",")",".","This","class","does","not","intend","to","satisfy","everyone","'s","preference","on","drawing","styles",".","This","visualizer","focuses","on","high","rendering","quality","rather","than","performance",".","It","is","not","designed","to","be","used","for","real-time","applications","."]
docstr: Create a grayscale version of the original image.
  The colors in masked area, if given, will be kept.
docstr_tok: ["Create","a","grayscale","version","of","the","original","image",".","The","colors","in","masked","area",",","if","given",",","will","be","kept","."]
code: def _create_grayscale_image(self, mask=None):
      """
      Create a grayscale version of the original image.
      The colors in masked area, if given, will be kept.
      """
      img_bw = self.img.astype("f4").mean(axis=2)
      img_bw = np.stack([img_bw] * 3, axis=2)
      if mask is not None:
          img_bw[mask] = self.img[mask]
      return img_bw
  
imports: import colorsys
  import logging
  import math
  import numpy
  from enum import Enum, unique
  import cv2
  import matplotlib
  import matplotlib.colors
  import matplotlib.figure
  import pycocotools.mask
  import torch
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  from PIL import Image
  from detectron2.data import MetadataCatalog
  from detectron2.structures import BitMasks, Boxes, BoxMode, Keypoints, PolygonMasks, RotatedBoxes
  from detectron2.utils.file_io import PathManager
  from .colormap import random_color
label_desc: Use image node_id 18 for calling the Visualizer obj's underlying member method code with example usage: obj._create_grayscale_image(mask) and returns: img_bw