def apply_crop(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor: r"""Apply cropping by src bounding box and dst bounding box. Order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in the x, y order. Args: input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W). params (Dict[str, torch.Tensor]): - params['src']: The applied cropping src matrix :math: `(*, 4, 2)`. - params['dst']: The applied cropping dst matrix :math: `(*, 4, 2)`. - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1. - params['align_corners']: Boolean tensor. Returns: torch.Tensor: The cropped input. """ input = _transform_input(input) _validate_input_dtype( input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) resample_mode: str = Resample.get( params['interpolation'].item()).name.lower() # type: ignore align_corners: bool = cast(bool, params['align_corners'].item()) return crop_by_boxes(input, params['src'], params['dst'], resample_mode, align_corners=align_corners)
def apply_crop(input: torch.Tensor, params: Dict[str, torch.Tensor], return_transform: bool = False) -> UnionType: """ Args: params (dict): A dict that must have {'src': torch.Tensor, 'dst': torch.Tensor}. Can be generated from kornia.augmentation.random_generator.random_crop_generator return_transform (bool): if ``True`` return the matrix describing the transformation applied to each input tensor. Returns: torch.Tensor: The grayscaled input torch.Tensor: The applied cropping matrix :math: `(*, 4, 2)` if return_transform flag is set to ``True`` """ input = _transform_input(input) _validate_input_dtype( input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) return crop_by_boxes( input, params['src'], params['dst'], Resample.get( params['interpolation'].item()).name.lower(), # type: ignore return_transform=return_transform)