code: def save(output_filename, labels, palette, dpi, options):
  
      '''Save the label/palette pair out as an indexed PNG image.  This
  optionally saturates the pallete by mapping the smallest color
  component to zero and the largest one to 255, and also optionally sets
  the background color to pure white.
  
      '''
  
      if not options.quiet:
          print('  saving {}...'.format(output_filename))
  
      if options.saturate:
          palette = palette.astype(np.float32)
          pmin = palette.min()
          pmax = palette.max()
          palette = 255 * (palette - pmin)/(pmax-pmin)
          palette = palette.astype(np.uint8)
  
      if options.white_bg:
          palette = palette.copy()
          palette[0] = (255, 255, 255)
  
      output_img = Image.fromarray(labels, 'P')
      output_img.putpalette(palette.flatten())
      output_img.save(output_filename, dpi=dpif save(output_filename, labels, palette, dpi, options):
  
      '''Save the label/palette pair out as an indexed PNG image.  This
  optionally saturates the pallete by mapping the smallest color
  component to zero and the largest one to 255, and also optionally sets
  the background color to pure white.
  
      '''
  
      if not options.quiet:
          print('  saving {}...'.format(output_filename))
  
      if options.saturate:
          palette = palette.astype(np.float32)
          pmin = palette.min()
          pmax = palette.max()
          palette = 255 * (palette - pmin)/(pmax-pmin)
          palette = palette.astype(np.uint8)
  
      if options.white_bg:
          palette = palette.copy()
          palette[0] = (255, 255, 255)
  
      output_img = Image.fromarray(labels, 'P')
      output_img.putpalette(palette.flatten())
      output_img.save(output_filename, dpi=dpi)
docs: Save the label/palette pair out as an indexed PNG image.  This
  optionally saturates the pallete by mapping the smallest color
  component to zero and the largest one to 255, and also optionally sets
  the background color to pure white.