code: def save_to_png(
      arr,
      path=None,
      image_mode=None,
      show=True,
      labels=None,
      scale=None,
  ):
      """Make a PNG and show it from a numpy array of dtype=np.uint8.
  
      Args:
        arr: numpy array. Input array to save.
        path: str. File path at which to save the image. A .png prefix is added if
          the path does not already have one. Leave empty to save at /tmp/tmp.png,
          which is useful when only temporarily showing the image in a Colab
          notebook.
        image_mode: "RGB" or "L". Leave as default=None to choose based on image
          dimensions.
        show: bool. Whether to display the image using IPython (for notebooks).
        labels: list of str. Labels to show across the top of the image.
        scale: integer. Number of pixels wide and tall to show each cell in the
          array. This sizes up the image while keeping exactly the same number of
          pixels for every cell in the array, preserving resolution and preventing
          any interpolation or overlapping of pixels. Default None adapts to the
          size of the image to multiply it up until a limit of 500 pixels, a
          convenient size for use in notebooks. If saving to a file for automated
          processing, scale=1 is recommended to keep output files small and simple
          while still retaining all the information content.
  
      Returns:
        None. Saves an image at path and optionally shows it with IPython.display.
      """
      if image_mode is None:
          image_mode = _get_image_type_from_array(arr)
  
      img = Image.fromarray(arr, mode=image_mode)
  
      if labels is not None:
          img = add_header(img, labels)
  
      if scale is None:
          scale = max(1, int(500 / max(arr.shape)))
  
      if scale != 1:
          img = img.resize((img.size[0] * scale, img.size[1] * scale))
  
      # Saving to a temporary file is needed even when showing in a notebook
      if path is None:
          path = "/tmp/tmp.png"
      elif not path.endswith(".png"):
          # Only PNG is supported because JPEG files are unnecessarily 3 times larger.
          path = "{}.png".format(path)
      img.save(epath.Path(path).open("wb"), format=path.split(".")[-1])
  
      # Show image (great for notebooks)
      if show:
          display.display(display.Image(path))
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import enum
  import math
  from typing import List, NamedTuple, Tuple
  from etils import epath
  from IPython import display
  import numpy
  from PIL import Image
  from PIL import ImageDraw
  from third_party.nucleus.protos import variants_pb2
label_desc: Use image node_id 9 for calling a global function with example usage: save_to_png(arr, path, image_mode, show, labels, scale) without return types