class_docstr: Loader that extracts text from images
code: def pad_resize_image(image):
      import cv2
  
      L = 1024
      H = 1024
  
      # Load the image
      Li, Hi = image.shape[1], image.shape[0]
  
      # Calculate the aspect ratio
      aspect_ratio_original = Li / Hi
      aspect_ratio_final = L / H
  
      # Check the original size and determine the processing needed
      if Li < L and Hi < H:
          # Padding
          padding_x = (L - Li) // 2
          padding_y = (H - Hi) // 2
          image = cv2.copyMakeBorder(
              image,
              padding_y,
              padding_y,
              padding_x,
              padding_x,
              cv2.BORDER_CONSTANT,
              value=[0, 0, 0],
          )
      elif Li > L and Hi > H:
          # Resizing
          if aspect_ratio_original < aspect_ratio_final:
              # The image is taller than the target aspect ratio
              new_height = H
              new_width = int(H * aspect_ratio_original)
          else:
              # The image is wider than the target aspect ratio
              new_width = L
              new_height = int(L / aspect_ratio_original)
          image = cv2.resize(
              image,
              (new_width, new_height),
              interpolation=cv2.INTER_AREA,
          )
      else:
          # Intermediate case, resize without cropping
          if aspect_ratio_original < aspect_ratio_final:
              # The image is taller than the target aspect ratio
              new_height = H
              new_width = int(H * aspect_ratio_original)
          else:
              # The image is wider than the target aspect ratio
              new_width = L
              new_height = int(L / aspect_ratio_original)
          image = cv2.resize(
              image,
              (new_width, new_height),
              interpolation=cv2.INTER_AREA,
          )
          padding_x = (L - new_width) // 2
          padding_y = (H - new_height) // 2
          image = cv2.copyMakeBorder(
              image,
              padding_y,
              padding_y,
              padding_x,
              padding_x,
              cv2.BORDER_CONSTANT,
              value=[0, 0, 0],
          )
      return image
  
imports: from typing import List, Union, Any, Tuple, Optional
  import requests
  import torch
  from langchain.docstore.document import Document
  from langchain.document_loaders import ImageCaptionLoader
  import numpy
  from utils import get_device, clear_torch_cache, NullContext
  from doctr.utils.common_types import AbstractFile
label_desc: Use image node_id 7 for calling the H2OOCRLoader obj's underlying member method code with example usage: obj.pad_resize_image(image) and returns: image