code: def crop_by_indices(
      input_tensor: Tensor,
      src_box: Tensor,
      size: Optional[Tuple[int, int]] = None,
      interpolation: str = "bilinear",
      align_corners: Optional[bool] = None,
      antialias: bool = False,
      shape_compensation: str = "resize",
  ) -> Tensor:
      """Crop tensors with naive indices.
  
      Args:
          input: the 2D image tensor with shape (B, C, H, W).
          src_box: a tensor with shape (B, 4, 2) containing the coordinates of the bounding boxes
              to be extracted. The tensor must have the shape of Bx4x2, where each box is defined in the clockwise
              order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in x, y order.
          size: output size. An auto resize or pad will be performed according to ``shape_compensation``
              if the cropped slice sizes are not exactly align `size`.
              If None, will auto-infer from src_box.
          interpolation:  algorithm used for upsampling: ``'nearest'`` | ``'linear'`` | ``'bilinear'`` |
              'bicubic' | 'trilinear' | 'area'.
          align_corners: interpolation flag.
          antialias: if True, then image will be filtered with Gaussian before downscaling.
              No effect for upscaling.
          shape_compensation: if the cropped slice sizes are not exactly align `size`, the image can either be padded
              or resized.
      """
      B, C, _, _ = input_tensor.shape
      src = as_tensor(
          src_box, device=input_tensor.device, dtype=torch.long
      )
      x1 = src[:, 0, 0]
      x2 = src[:, 1, 0] + 1
      y1 = src[:, 0, 1]
      y2 = src[:, 3, 1] + 1
  
      if (
          len(x1.unique(sorted=False))
          == len(x2.unique(sorted=False))
          == len(y1.unique(sorted=False))
          == len(y2.unique(sorted=False))
          == 1
      ):
          out = input_tensor[
              ..., int(y1[0]) : int(y2[0]), int(x1[0]) : int(x2[0])
          ]
          if size is not None and out.shape[-2:] != size:
              return resize(
                  out,
                  size,
                  interpolation=interpolation,
                  align_corners=align_corners,
                  side="short",
                  antialias=antialias,
              )
  
      if size is None:
          h, w = infer_bbox_shape(src)
          size = h.unique(sorted=False), w.unique(sorted=False)
      out = torch.empty(
          B,
          C,
          *size,
          device=input_tensor.device,
          dtype=input_tensor.dtype,
      )
      # Find out the cropped shapes that need to be resized.
      for i, _ in enumerate(out):
          _out = input_tensor[
              i : i + 1,
              :,
              int(y1[i]) : int(y2[i]),
              int(x1[i]) : int(x2[i]),
          ]
          if _out.shape[-2:] != size:
              if shape_compensation == "resize":
                  out[i] = resize(
                      _out,
                      size,
                      interpolation=interpolation,
                      align_corners=align_corners,
                      side="short",
                      antialias=antialias,
                  )
              else:
                  out[i] = pad(
                      _out,
                      [
                          0,
                          size[1] - _out.shape[-1],
                          0,
                          size[0] - _out.shape[-2],
                      ],
                  )
          else:
              out[i] = _out
      return out
  
file_path: kornia/kornia/geometry/transform/crop2d.py
imports: from typing import Optional, Tuple
  import torch
  from kornia.core import Tensor, as_tensor, pad, tensor
  from kornia.geometry.bbox import infer_bbox_shape, validate_bbox
  from .affwarp import resize
  from .imgwarp import get_perspective_transform, warp_affine
label_desc: Use image node_id 5 for calling a global function with example usage: crop_by_indices(input_tensor, src_box, size, interpolation, align_corners, antialias, shape_compensation) and returns: out, resize