code: def crop_by_transform_mat(
      input_tensor: Tensor,
      transform: Tensor,
      out_size: Tuple[int, int],
      mode: str = "bilinear",
      padding_mode: str = "zeros",
      align_corners: bool = True,
  ) -> Tensor:
      """Perform crop transform on 2D images (4D tensor) given a perspective transformation matrix.
  
      Args:
          input_tensor: the 2D image tensor with shape (B, C, H, W).
          transform: a perspective transformation matrix with shape (B, 3, 3).
          out_size: size of the output image (height, width).
          mode: interpolation mode to calculate output values
            ``'bilinear'`` | ``'nearest'``.
          padding_mode (str): padding mode for outside grid values
            ``'zeros'`` | ``'border'`` | ``'reflection'``.
          align_corners: mode for grid_generation.
  
      Returns:
          the output tensor with patches.
      """
      # simulate broadcasting
      dst_trans_src = as_tensor(
          transform.expand(input_tensor.shape[0], -1, -1),
          device=input_tensor.device,
          dtype=input_tensor.dtype,
      )
  
      patches: Tensor = warp_affine(
          input_tensor,
          dst_trans_src[:, :2, :],
          out_size,
          mode=mode,
          padding_mode=padding_mode,
          align_corners=align_corners,
      )
  
      return patches
  
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 4 for calling a global function with example usage: crop_by_transform_mat(input_tensor, transform, out_size, mode, padding_mode, align_corners) and returns: patches