code: def crop_image(img, padding=5):
      "Crops an image or slice to its extents"
  
      if padding < 1:
          return img
  
      beg_coords, end_coords = crop_coords(img, padding)
  
      if len(img.shape) == 3:
          img = crop_3dimage(img, beg_coords, end_coords)
      elif len(img.shape) == 2:
          img = crop_2dimage(img, beg_coords, end_coords)
      else:
          raise ValueError('Can only crop 2D or 3D images!')
  
      return imf crop_image(img, padding=5):
      "Crops an image or slice to its extents"
  
      if padding < 1:
          return img
  
      beg_coords, end_coords = crop_coords(img, padding)
  
      if len(img.shape) == 3:
          img = crop_3dimage(img, beg_coords, end_coords)
      elif len(img.shape) == 2:
          img = crop_2dimage(img, beg_coords, end_coords)
      else:
          raise ValueError('Can only crop 2D or 3D images!')
  
      return img
docs: Crops an image or slice to its extents