code: def check_type_and_cast_if_necessary(img, as_uint16):
      if not as_uint16 and img.dtype == np.uint16:
          raise ValueError(
              "Input img type is uint16, but as_uint16 is False."
              " If you want to save img as uint8, be sure all pixel values are in the range of [0, 255]"
              " and cast it before you call imsave function."
          )
  
      if as_uint16 and img.dtype != np.uint16:
          # in the case of as_uint16 is True and upscale is False. Save uint8 as uint16 without scaling.
          logger.warning(
              "Save image as uint16, but the original input image type is not uint16"
          )
          img = np.asarray(img, np.uint16)
  
      return img
  
file_path: nnabla/python/src/nnabla/utils/image_utils/backend_events/common.py
imports: from __future__ import division, absolute_import
  import numpy
  from nnabla.logger import logger
label_desc: Use image node_id 6 for calling a global function with example usage: check_type_and_cast_if_necessary(img, as_uint16) and returns: img