code: def rescale_image(
      image: np.ndarray, scale_factor: float
  ) -> np.ndarray:
      """Resize an image by a scale factor, using integer resizing if possible."""
      scale_factor = float(scale_factor)
      if scale_factor <= 0.0:
          raise ValueError(
              "scale_factor must be a non-negative number."
          )
  
      if scale_factor == 1.0:
          return image
  
      height, width = image.shape[:2]
      if scale_factor.is_integer():
          return upsample_image(image, int(scale_factor))
  
      inv_scale = 1.0 / scale_factor
      if (
          inv_scale.is_integer()
          and (scale_factor * height).is_integer()
          and (scale_factor * width).is_integer()
      ):
          return downsample_image(image, int(inv_scale))
  
      logging.warning(
          "resizing image by non-integer factor %f, this may lead to artifacts.",
          scale_factor,
      )
  
      height, width = image.shape[:2]
      out_height = math.ceil(height * scale_factor)
      out_height -= out_height % 2
      out_width = math.ceil(width * scale_factor)
      out_width -= out_width % 2
  
      return reshape_image(image, (out_height, out_width))
  
imports: import math
  from typing import Tuple
  from absl import logging
  import cv2
  import imageio
  import numpy
  from PIL import Image
  from nerfies import gpath
  from nerfies import types
label_desc: Use image node_id 5 for calling a global function with example usage: rescale_image(image, scale_factor) and returns: reshape_image, image, upsample_image, downsample_image