code: def convert_channel_from_gray(img, num_channels):
      if num_channels in [-1, 0]:
          return img
  
      elif num_channels == 1:
          return img[..., np.newaxis]
  
      elif num_channels == 3:  # GRAY => RGB (just expand)
          return cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
  
      elif num_channels == 4:  # GRAY => RGBA (just expand)
          return cv2.cvtColor(img, cv2.COLOR_GRAY2RGBA)
  
      raise ValueError("num_channels must be [-1, 0, 1, 3, 4]")
  
file_path: nnabla/python/src/nnabla/utils/image_utils/backend_events/cv2_backend.py
imports: from __future__ import absolute_import, division
  import cv2
  import numpy
  from nnabla.logger import logger
  from .common import upscale_pixel_intensity, check_type_and_cast_if_necessary, _imread_before, _imread_after, _imsave_before, _imresize_before, _imresize_after
  from .image_utils_backend import ImageUtilsBackend
label_desc: Use image node_id 3 for calling the Cv2Backend obj's underlying member method code with example usage: obj.convert_channel_from_gray(img, num_channels) and returns: img, img, cv2, cv2