code: def pad_nd_image(
      image,
      new_shape=None,
      mode="edge",
      kwargs=None,
      return_slicer=False,
      shape_must_be_divisible_by=None,
  ):
      """
      one padder to pad them all. Documentation? Well okay. A little bit. by Fabian Isensee
  
      :param image: nd image. can be anything
      :param new_shape: what shape do you want? new_shape does not have to have the same dimensionality as image. If
      len(new_shape) < len(image.shape) then the last axes of image will be padded. If new_shape < image.shape in any of
      the axes then we will not pad that axis, but also not crop! (interpret new_shape as new_min_shape)
      Example:
      image.shape = (10, 1, 512, 512); new_shape = (768, 768) -> result: (10, 1, 768, 768). Cool, huh?
      image.shape = (10, 1, 512, 512); new_shape = (364, 768) -> result: (10, 1, 512, 768).
  
      :param mode: see np.pad for documentation
      :param return_slicer: if True then this function will also return what coords you will need to use when cropping back
      to original shape
      :param shape_must_be_divisible_by: for network prediction. After applying new_shape, make sure the new shape is
      divisibly by that number (can also be a list with an entry for each axis). Whatever is missing to match that will
      be padded (so the result may be larger than new_shape if shape_must_be_divisible_by is not None)
      :param kwargs: see np.pad for documentation
      """
      if kwargs is None:
          kwargs = {}
  
      if new_shape is not None:
          old_shape = np.array(image.shape[-len(new_shape) :])
      else:
          assert shape_must_be_divisible_by is not None
          assert isinstance(
              shape_must_be_divisible_by, (list, tuple, np.ndarray)
          )
          new_shape = image.shape[-len(shape_must_be_divisible_by) :]
          old_shape = new_shape
  
      num_axes_nopad = len(image.shape) - len(new_shape)
  
      new_shape = [
          max(new_shape[i], old_shape[i]) for i in range(len(new_shape))
      ]
  
      if not isinstance(new_shape, np.ndarray):
          new_shape = np.array(new_shape)
  
      if shape_must_be_divisible_by is not None:
          if not isinstance(
              shape_must_be_divisible_by, (list, tuple, np.ndarray)
          ):
              shape_must_be_divisible_by = [
                  shape_must_be_divisible_by
              ] * len(new_shape)
          else:
              assert len(shape_must_be_divisible_by) == len(new_shape)
  
          for i in range(len(new_shape)):
              if new_shape[i] % shape_must_be_divisible_by[i] == 0:
                  new_shape[i] -= shape_must_be_divisible_by[i]
  
          new_shape = np.array(
              [
                  new_shape[i]
                  + shape_must_be_divisible_by[i]
                  - new_shape[i] % shape_must_be_divisible_by[i]
                  for i in range(len(new_shape))
              ]
          )
  
      difference = new_shape - old_shape
      pad_below = difference // 2
      pad_above = difference // 2 + difference % 2
      pad_list = [[0, 0]] * num_axes_nopad + list(
          [list(i) for i in zip(pad_below, pad_above)]
      )
      res = np.pad(image, pad_list, mode, **kwargs)
      if not return_slicer:
          return res
      else:
          pad_list = np.array(pad_list)
          pad_list[:, 1] = np.array(res.shape) - pad_list[:, 1]
          slicer = list(slice(*i) for i in pad_list)
          return res, slicer
  
file_path: medicaldetectiontoolkit/utils/dataloader_utils.py
imports: import numpy
  import os
  from multiprocessing import Pool
label_desc: Use image node_id 3 for calling a global function with example usage: pad_nd_image(image, new_shape, mode, kwargs, return_slicer, shape_must_be_divisible_by) and returns: res, res,  slicer