code: def test_imsave_and_imread(
      tmpdir,
      backend,
      grayscale,
      size,
      channel_first,
      as_uint16,
      num_channels,
      auto_scale,
      img,
  ):
      # import pdb
      # pdb.set_trace()
      # preprocess
      _change_backend(backend)
  
      tmpdir.ensure(dir=True)
      tmppath = tmpdir.join("tmp.png")
      img_file = tmppath.strpath
  
      ref_size_axis = 0
      if channel_first and len(img.shape) == 3:
          img = img.transpose((2, 0, 1))
          ref_size_axis = 1
  
      # do imsave
      def save_image_function():
          image_utils.imsave(
              img_file,
              img,
              channel_first=channel_first,
              as_uint16=as_uint16,
              auto_scale=auto_scale,
          )
  
      if check_imsave_condition(backend, img, as_uint16, auto_scale):
          save_image_function()
      else:
          with pytest.raises(ValueError):
              save_image_function()
  
          return
  
      # do imread
      def read_image_function():
          return image_utils.imread(
              img_file,
              grayscale=grayscale,
              size=size,
              channel_first=channel_first,
              as_uint16=as_uint16,
              num_channels=num_channels,
          )
  
      if not grayscale and num_channels in [0, 1]:
          with pytest.raises(ValueError):
              _ = read_image_function()
  
          return
      else:
          read_image = read_image_function()
  
      logger.info(read_image.shape)
      # ---check size---
      ref_size = (
          img.shape[ref_size_axis : ref_size_axis + 2]
          if size is None
          else size
      )
      size_axis = (
          1 if len(read_image.shape) == 3 and channel_first else 0
      )
      assert read_image.shape[size_axis : size_axis + 2] == ref_size
  
      # ---check channels---
      if num_channels == 0 or (
          num_channels == -1 and (len(img.shape) == 2 or grayscale)
      ):
          assert len(read_image.shape) == 2
      else:
          channel_axis = 0 if channel_first else -1
          ref_channels = (
              num_channels
              if num_channels > 0
              else img.shape[channel_axis]
          )
          assert read_image.shape[channel_axis] == ref_channels
  
      # ---check dtype---
      if as_uint16 or img.dtype == np.uint16:
          assert read_image.dtype == np.uint16
      else:
          assert read_image.dtype == np.uint8
  
      # ---check close between before imsave and after imread---
      if (
          size is None
          and not grayscale
          and img.shape == read_image.shape
      ):
          scaler = get_scale_factor(img, auto_scale, as_uint16)
          dtype = (
              img.dtype
              if img.dtype in [np.uint8, np.uint16]
              else np.float32
          )
  
          assert_allclose(
              (img.astype(dtype) * scaler).astype(read_image.dtype),
              read_image,
          )
  
file_path: nnabla/python/test/utils/test_image_utils.py
imports: from __future__ import division
  import pytest
  import numpy
  from nnabla.utils import image_utils
  from nnabla.logger import logger
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 5 for calling a global function with example usage: test_imsave_and_imread(tmpdir, backend, grayscale, size, channel_first, as_uint16, num_channels, auto_scale, img) and returns: image_utils