code: def pad(
      img, shape=None, padding=None, pad_val=0, padding_mode="constant"
  ):
      assert (shape is not None) ^ (padding is not None)
      if shape is not None:
          width = max(shape[1] - img.shape[1], 0)
          height = max(shape[0] - img.shape[0], 0)
          padding = (0, 0, width, height)
  
      # Check pad_val
      if isinstance(pad_val, tuple):
          assert len(pad_val) == img.shape[-1]
      elif not isinstance(pad_val, numbers.Number):
          raise TypeError(
              "pad_val must be a int or a tuple. "
              f"But received {type(pad_val)}"
          )
  
      # Check padding
      if isinstance(padding, tuple) and len(padding) in [2, 4]:
          if len(padding) == 2:
              padding = (padding[0], padding[1], padding[0], padding[1])
      elif isinstance(padding, numbers.Number):
          padding = (padding, padding, padding, padding)
      else:
          raise ValueError(
              "Padding must be a int or a 2, or 4 element tuple."
              f"But received {padding}"
          )
  
      # Check padding mode
      assert padding_mode in [
          "constant",
          "edge",
          "reflect",
          "symmetric",
      ]
  
      border_type = {
          "constant": cv2.BORDER_CONSTANT,
          "edge": cv2.BORDER_REPLICATE,
          "reflect": cv2.BORDER_REFLECT_101,
          "symmetric": cv2.BORDER_REFLECT,
      }
      img = cv2.copyMakeBorder(
          img,
          padding[1],
          padding[3],
          padding[0],
          padding[2],
          border_type[padding_mode],
          value=pad_val,
      )
  
      return img
  
file_path: PaddleSeg/contrib/RSSegBenchmark/data/prepare_isaid.py
imports: import argparse
  import glob
  import os
  import os.path
  import shutil
  import tempfile
  import zipfile
  import cv2
  import numpy
  from tqdm import tqdm
  from PIL import Image
label_desc: Use image node_id 3 for calling a global function with example usage: pad(img, shape, padding, pad_val, padding_mode) and returns: img