code: def resize_image_with_crop_or_pad(
      image, img_size=(64, 64, 64), **kwargs
  ):
      """Image resizing. Resizes image by cropping or padding dimension
       to fit specified size.
  
      Args:
          image (np.ndarray): image to be resized
          img_size (list or tuple): new image size
          kwargs (): additional arguments to be passed to np.pad
  
      Returns:
          np.ndarray: resized image
      """
  
      assert isinstance(image, (np.ndarray, np.generic))
      assert image.ndim - 1 == len(img_size) or image.ndim == len(
          img_size
      ), "Example size doesnt fit image size"
  
      # Get the image dimensionality
      rank = len(img_size)
  
      # Create placeholders for the new shape
      from_indices = [[0, image.shape[dim]] for dim in range(rank)]
      to_padding = [[0, 0] for dim in range(rank)]
  
      slicer = [slice(None)] * rank
  
      # For each dimensions find whether it is supposed to be cropped or padded
      for i in range(rank):
          if image.shape[i] < img_size[i]:
              to_padding[i][0] = (img_size[i] - image.shape[i]) // 2
              to_padding[i][1] = (
                  img_size[i] - image.shape[i] - to_padding[i][0]
              )
          else:
              from_indices[i][0] = int(
                  np.floor((image.shape[i] - img_size[i]) / 2.0)
              )
              from_indices[i][1] = from_indices[i][0] + img_size[i]
  
          # Create slicer object to crop or leave each dimension
          slicer[i] = slice(from_indices[i][0], from_indices[i][1])
  
      # Pad the cropped image to extend the missing dimension
      return np.pad(image[slicer], to_padding, **kwargs)
  
file_path: DLTK/dltk/io/preprocessing.py
imports: from __future__ import unicode_literals
  from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: resize_image_with_crop_or_pad(image, img_size) and returns: np