docstr: Save image by pypng module.
  
  Args:
      path (str): output filename
      img (numpy.ndarray): Image array to save. Image shape is considered as (height, width, channel) by default.
      channel_first:
          This argument specifies the shape of img is whether (height, width, channel) or (channel, height, width).
          Default value is False, which means the img shape is (height, width, channel)
      as_uint16 (bool):
          If True, save image as uint16.
      auto_scale (bool) :
          Whether upscale pixel values or not.
          If you want to save float image, this argument must be True.
          In pypng backend, all below are supported.
              - float ([0, 1]) to uint8 ([0, 255])  (if img.dtype==float and upscale==True and as_uint16==False)
              - float to uint16 ([0, 65535]) (if img.dtype==float and upscale==True and as_uint16==True)
              - uint8 to uint16 are supported (if img.dtype==np.uint8 and upscale==True and as_uint16==True)
docstr_tok: ["Save","image","by","pypng","module",".","Args",":","path","(","str",")",":","output","filename","img","(","numpy.ndarray",")",":","Image","array","to","save",".","Image","shape","is","considered","as","(","height",",","width",",","channel",")","by","default",".","channel_first",":","This","argument","specifies","the","shape","of","img","is","whether","(","height",",","width",",","channel",")","or","(","channel",",","height",",","width",")",".","Default","value","is","False",",","which","means","the","img","shape","is","(","height",",","width",",","channel",")","as_uint16","(","bool",")",":","If","True",",","save","image","as","uint16",".","auto_scale","(","bool",")",":","Whether","upscale","pixel","values","or","not",".","If","you","want","to","save","float","image",",","this","argument","must","be","True",".","In","pypng","backend",",","all","below","are","supported",".","-","float","(","[","0",",","1","]",")","to","uint8","(","[","0",",","255","]",")","(","if","img.dtype==float","and","upscale==True","and","as_uint16==False",")","-","float","to","uint16","(","[","0",",","65535","]",")","(","if","img.dtype==float","and","upscale==True","and","as_uint16==True",")","-","uint8","to","uint16","are","supported","(","if","img.dtype==np.uint8","and","upscale==True","and","as_uint16==True",")"]
code: def imsave(
      self,
      path,
      img,
      channel_first=False,
      as_uint16=False,
      auto_scale=True,
  ):
      """
      Save image by pypng module.
  
      Args:
          path (str): output filename
          img (numpy.ndarray): Image array to save. Image shape is considered as (height, width, channel) by default.
          channel_first:
              This argument specifies the shape of img is whether (height, width, channel) or (channel, height, width).
              Default value is False, which means the img shape is (height, width, channel)
          as_uint16 (bool):
              If True, save image as uint16.
          auto_scale (bool) :
              Whether upscale pixel values or not.
              If you want to save float image, this argument must be True.
              In pypng backend, all below are supported.
                  - float ([0, 1]) to uint8 ([0, 255])  (if img.dtype==float and upscale==True and as_uint16==False)
                  - float to uint16 ([0, 65535]) (if img.dtype==float and upscale==True and as_uint16==True)
                  - uint8 to uint16 are supported (if img.dtype==np.uint8 and upscale==True and as_uint16==True)
      """
  
      img = _imsave_before(img, channel_first, auto_scale)
  
      if auto_scale:
          img = upscale_pixel_intensity(img, as_uint16)
  
      img = check_type_and_cast_if_necessary(img, as_uint16)
  
      bitdepth = 8 if img.dtype == np.uint8 else 16
      grayscale = (
          True
          if len(img.shape) == 2
          or (len(img.shape) == 3 and img.shape[-1] == 1)
          else False
      )
  
      writer = png.Writer(
          img.shape[1],
          img.shape[0],
          greyscale=grayscale,
          bitdepth=bitdepth,
      )
  
      writer.write(open(path, "wb"), img.reshape(img.shape[0], -1))
  
file_path: nnabla/python/src/nnabla/utils/image_utils/backend_events/pypng_backend.py
imports: from __future__ import absolute_import, division
  import numpy
  import png
  from nnabla.logger import logger
  from .common import upscale_pixel_intensity, check_type_and_cast_if_necessary, _imread_before, _imread_after, _imsave_before
  from .image_utils_backend import ImageUtilsBackend
label_desc: Use image node_id 7 for calling the PngBackend obj's underlying member method code with example usage: obj.imsave(path, img, channel_first, as_uint16, auto_scale) without return types