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.
docstr: Args:
      binary_mask (ndarray): numpy array of shape (H, W), where H is the image height and
          W is the image width. Each value in the array is either a 0 or 1 value of uint8
          type.
      color: color of the mask. Refer to `matplotlib.colors` for a full list of
          formats that are accepted. If None, will pick a random color.
      edge_color: color of the polygon edges. Refer to `matplotlib.colors` for a
          full list of formats that are accepted.
      text (str): if None, will be drawn in the object's center of mass.
      alpha (float): blending efficient. Smaller values lead to more transparent masks.
      area_threshold (float): a connected component small than this will not be shown.
  
  Returns:
      output (VisImage): image object with mask drawn.
docstr_tok: ["Args",":","binary_mask","(","ndarray",")",":","numpy","array","of","shape","(","H",",","W",")",",","where","H","is","the","image","height","and","W","is","the","image","width",".","Each","value","in","the","array","is","either","a","0","or","1","value","of","uint8","type",".","color",":","color","of","the","mask",".","Refer","to","`","matplotlib.colors","`","for","a","full","list","of","formats","that","are","accepted",".","If","None",",","will","pick","a","random","color",".","edge_color",":","color","of","the","polygon","edges",".","Refer","to","`","matplotlib.colors","`","for","a","full","list","of","formats","that","are","accepted",".","text","(","str",")",":","if","None",",","will","be","drawn","in","the","object","'s","center","of","mass",".","alpha","(","float",")",":","blending","efficient",".","Smaller","values","lead","to","more","transparent","masks",".","area_threshold","(","float",")",":","a","connected","component","small","than","this","will","not","be","shown",".","Returns",":","output","(","VisImage",")",":","image","object","with","mask","drawn","."]
code: def draw_binary_mask(
      self,
      binary_mask,
      color=None,
      *,
      edge_color=None,
      text=None,
      alpha=0.5,
      area_threshold=0,
  ):
      """
      Args:
          binary_mask (ndarray): numpy array of shape (H, W), where H is the image height and
              W is the image width. Each value in the array is either a 0 or 1 value of uint8
              type.
          color: color of the mask. Refer to `matplotlib.colors` for a full list of
              formats that are accepted. If None, will pick a random color.
          edge_color: color of the polygon edges. Refer to `matplotlib.colors` for a
              full list of formats that are accepted.
          text (str): if None, will be drawn in the object's center of mass.
          alpha (float): blending efficient. Smaller values lead to more transparent masks.
          area_threshold (float): a connected component small than this will not be shown.
  
      Returns:
          output (VisImage): image object with mask drawn.
      """
      if mask_util is None:
          raise ImportError("Unable to import pycocotools")
      if color is None:
          color = random_color(rgb=True, maximum=1)
      color = mplc.to_rgb(color)
  
      has_valid_segment = False
      binary_mask = binary_mask.astype("uint8")  # opencv needs uint8
      mask = GenericMask(
          binary_mask, self.output.height, self.output.width
      )
      shape2d = (binary_mask.shape[0], binary_mask.shape[1])
  
      if not mask.has_holes:
          # draw polygons for regular masks
          for segment in mask.polygons:
              area = mask_util.area(
                  mask_util.frPyObjects(
                      [segment], shape2d[0], shape2d[1]
                  )
              )
              if area < (area_threshold or 0):
                  continue
              has_valid_segment = True
              segment = segment.reshape(-1, 2)
              self.draw_polygon(
                  segment,
                  color=color,
                  edge_color=edge_color,
                  alpha=alpha,
              )
      else:
          # TODO: Use Path/PathPatch to draw vector graphics:
          # https://stackoverflow.com/questions/8919719/how-to-plot-a-complex-polygon
          rgba = np.zeros(shape2d + (4,), dtype="float32")
          rgba[:, :, :3] = color
          rgba[:, :, 3] = (mask.mask == 1).astype("float32") * alpha
          has_valid_segment = True
          self.output.ax.imshow(
              rgba, extent=(0, self.output.width, self.output.height, 0)
          )
  
      if text is not None and has_valid_segment:
          if cv2 is None:
              raise ImportError("Unable to import cv2")
          # TODO sometimes drawn on wrong objects. the heuristics here can improve.
          lighter_color = self._change_color_brightness(
              color, brightness_factor=0.7
          )
          (
              _num_cc,
              cc_labels,
              stats,
              centroids,
          ) = cv2.connectedComponentsWithStats(binary_mask, 8)
          largest_component_id = np.argmax(stats[1:, -1]) + 1
  
          # draw text on the largest component, as well as other very large components.
          for cid in range(1, _num_cc):
              if (
                  cid == largest_component_id
                  or stats[cid, -1] > _LARGE_MASK_AREA_THRESH
              ):
                  # median is more stable than centroid
                  # center = centroids[largest_component_id]
                  center = np.median(
                      (cc_labels == cid).nonzero(), axis=1
                  )[::-1]
                  self.draw_text(text, center, color=lighter_color)
      return self.output
  
imports: import colorsys
  import logging
  import math
  from enum import Enum, unique
  import numpy
  import matplotlib
  import matplotlib.colors
  import matplotlib.figure
  import torch
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  from PIL import Image
  from ..data.registry.catalog import MetadataCatalog
  from ..data.structures import BitMasks, Boxes, BoxMode, Keypoints, PolygonMasks
label_desc: Use image node_id 14 for calling the Visualizer obj's underlying member method code with example usage: obj.draw_binary_mask(binary_mask, color) and returns: self