code: def resize_image(path_to_image, reshaped_dir):
      """
      Function to resize given image retaining original aspect ratio and save in given directory 'reshaped_dir'.
      Returns numpy array of resized image and path where resized file is saved.
      Note:
      Azure COGS CV has size limit of < 4MB and min size of 50x50 for images.
      Hence, large image files are being reshaped in code below to increase speed of SHAP explanations and run Azure COGS for image captions.
      If image (pixel_size, pixel_size) is greater than 500 for either of the dimensions:
      1 - image is resized to have max. 500 pixel size for the dimension > 500
      2 - other dimension is resized retaining the original aspect ratio
      """
      image = load_image(path_to_image)
  
      # checking if either of (pixel_size, pixel_size) dimension is greater than 500.
      reshaped_path = None
      _, tail = os.path.split(path_to_image)
      file_name = tail.split(".")[0]
      max_pixels = 500
      reshape = True
  
      if image.shape[0] == image.shape[1] and image.shape[0] > 500:
          new_dim = (max_pixels, max_pixels)
      elif image.shape[0] > image.shape[1] and image.shape[0] > 500:
          new_dim = (
              max_pixels,
              int(image.shape[1] * max_pixels / image.shape[0]),
          )
      elif image.shape[1] > image.shape[0] and image.shape[1] > 500:
          new_dim = (
              int(image.shape[0] * max_pixels / image.shape[1]),
              max_pixels,
          )
      else:
          reshape = False
  
      # reshape image
      if reshape:
          # flipping axis for cv2 because cv2 uses width x height while numpy uses height x width
          image = cv2.resize(image, dsize=(new_dim[1], new_dim[0]))
          reshaped_path = os.path.join(reshaped_dir, file_name + ".png")
          print("Reshaped image size:", image.shape)
          save_image(image, reshaped_path)
          image = np.array(image).astype("float")
  
      return image, reshaped_path
  
file_path: shap/shap/utils/image.py
imports: import os
  from textwrap import wrap
  import cv2
  import matplotlib.pyplot
  import numpy
  import shap
label_desc: Use image node_id 7 for calling a global function with example usage: resize_image(path_to_image, reshaped_dir) and returns: image,  reshaped_path