code: def _serialize_normalized_array(array, fmt="png", quality=70):
      """Given a normalized array, returns byte representation of image encoding.
  
      Args:
        array: NumPy array of dtype uint8 and range 0 to 255
        fmt: string describing desired file format, defaults to 'png'
        quality: specifies compression quality from 0 to 100 for lossy formats
  
      Returns:
        image data as BytesIO buffer
      """
      dtype = array.dtype
      assert np.issubdtype(dtype, np.unsignedinteger)
      assert np.max(array) <= np.iinfo(dtype).max
      assert array.shape[-1] > 1  # array dims must have been squeezed
  
      image = PIL.Image.fromarray(array)
      image_bytes = BytesIO()
      image.save(image_bytes, fmt, quality=quality)
      # TODO: Python 3 could save a copy here by using `getbuffer()` instead.
      image_data = image_bytes.getvalue()
      return image_data
  
file_path: lucid/lucid/misc/io/serialize_array.py
imports: from __future__ import absolute_import, division, print_function
  import base64
  import logging
  import numpy
  import PIL.Image
  from io import BytesIO
label_desc: Use image node_id 2 for calling a global function with example usage: _serialize_normalized_array(array, fmt, quality) and returns: image_data