parameters: (img, mean, std)
return_statement: return img
docstring: Function for normalizing image.
      Args::
      [in] image(PIL Image.Image or np.ndarray): input image.
           If type of input image is np.ndarray, it should be in shape (C, H, W). 
      [in] mean(list): the mean value of Normalization.
      [in] std(list): the std value of Normalization.
      Example::
          img = Image.open(...)
          img_ = transform.image_normalize(img, mean=[0.5], std=[0.5])
docstring_summary: Function for normalizing image.
      Args::
      [in] image(PIL Image.Image or np.ndarray): input image.
           If type of input image is np.ndarray, it should be in shape (C, H, W). 
      [in] mean(list): the mean value of Normalization.
      [in] std(list): the std value of Normalization.
      Example::
          img = Image.open(...)
          img_ = transform.image_normalize(img, mean=[0.5], std=[0.5])
docstring_tokens: Function for normalizing image . Args :: [ in ] image ( PIL Image . Image or np . ndarray ) : input image . If type of input image is np . ndarray it should be in shape ( C H W ) . [ in ] mean ( list ) : the mean value of Normalization . [ in ] std ( list ) : the std value of Normalization . Example :: img = Image . open ( ... ) img_ = transform . image_normalize ( img mean = [ 0 . 5 ] std = [ 0 . 5 ] )
function: def image_normalize(img, mean, std):
      """
      Function for normalizing image.
      Args::
      [in] image(PIL Image.Image or np.ndarray): input image.
           If type of input image is np.ndarray, it should be in shape (C, H, W). 
      [in] mean(list): the mean value of Normalization.
      [in] std(list): the std value of Normalization.
      Example::
          img = Image.open(...)
          img_ = transform.image_normalize(img, mean=[0.5], std=[0.5])
      """
      if not isinstance(img, (Image.Image, jt.Var, np.ndarray)):
          raise TypeError(f'Input type should be in (PIL Image, jt.Var, np.ndarray). Got {type(img)}.')
      elif isinstance(img, Image.Image):
          assert img.mode == 'RGB', f"input image mode should be 'RGB'. Got {img.mode}."
          img = (np.array(img).transpose((2, 0, 1)) \
                 - mean * np.float32(255.)) \
                 / (std * np.float32(255.))
      else:
          if img.ndim < 3:
              raise ValueError(f'Expected input to be a array image of size (..., C, H, W). Got {img.shape}.')
          if isinstance(img, jt.Var):
              mean = jt.array(mean)
              std = jt.array(std)
              if (std.data == 0).any():
                  raise ValueError('std cannot be zero.')
          else:
              mean = np.asarray(mean)
              std = np.asarray(std)
              if (std == 0).any():
                  raise ValueError('std cannot be zero.')
          if mean.ndim == 1:
              mean = mean.reshape(-1, 1, 1)
          if std.ndim == 1:
              std = std.reshape(-1, 1, 1)
          img = (img - mean) / std
      return img
function_tokens: def image_normalize ( img , mean , std ) : if not isinstance ( img , ( Image . Image , jt . Var , np . ndarray ) ) : raise TypeError ( f'Input type should be in (PIL Image, jt.Var, np.ndarray). Got {type(img)}.' ) elif isinstance ( img , Image . Image ) : assert img . mode == 'RGB' , f"input image mode should be 'RGB'. Got {img.mode}." img = ( np . array ( img ) . transpose ( ( 2 , 0 , 1 ) ) - mean * np . float32 ( 255. ) ) / ( std * np . float32 ( 255. ) ) else : if img . ndim < 3 : raise ValueError ( f'Expected input to be a array image of size (..., C, H, W). Got {img.shape}.' ) if isinstance ( img , jt . Var ) : mean = jt . array ( mean ) std = jt . array ( std ) if ( std . data == 0 ) . any ( ) : raise ValueError ( 'std cannot be zero.' ) else : mean = np . asarray ( mean ) std = np . asarray ( std ) if ( std == 0 ) . any ( ) : raise ValueError ( 'std cannot be zero.' ) if mean . ndim == 1 : mean = mean . reshape ( - 1 , 1 , 1 ) if std . ndim == 1 : std = std . reshape ( - 1 , 1 , 1 ) img = ( img - mean ) / std return img