Repository: kornia/kornia

Issue:
RandomCrop, CenterCrop and RandomResizeCrop doesn't crop bbox or keypoints when cropping_mode="slice"
### Describe the bug

RandomCrop, CenterCrop and RandomResizeCrop doesn't crop bbox or keypoint inputs when cropping_mode is "slice".  Mask inputs works fines.

Note that using cropping_mode="resample" works fine. 

### Reproduction steps

```bash
Download panda image: `wget https://tinypng.com/images/social/website.jpg -O panda.jpg`


import torch
import kornia.augmentation as K
import torchvision
from kornia.utils import draw_rectangle, tensor_to_image

def plot(image, bbox, mask=None):
    if mask is not None:
        image *= mask.any(dim=1) # Collapse all masks from different boxes
    img_draw = draw_rectangle(image.clone().detach(), bbox, color=torch.as_tensor([255., 0, 0]))
    plt.imshow(tensor_to_image(img_draw)); plt.axis('off');

# Inputs
image = torchvision.io.read_image('panda.jpg').unsqueeze(0).float() / 255.
boxes = torch.tensor([[[355,10, 660,250], [10,125, 200,400]]])
mask = Boxes.from_tensor(boxes, mode="xyxy").to_mask(*image.shape[-2:])

plot(image, boxes)

aug = K.AugmentationSequential(
   K.RandomCrop((500,500), p=1, cropping_mode="slice"), # <- works with cropping_mode="resampling"
   data_keys=["input", "bbox_xyxy", "mask"],  
)

tfm_img, tfm_bbox, tfm_mask = aug(image, boxes, mask)
```


### Expected behavior

Do crop for bbox and keypoints like any other transform does. 

### Environment

```shell
Kornia 0.6.5
Pytorch 1.9.1+cpu
```


### Additional context

_No response_

*Edit: add RandomResizeCrop and remove 3D version of these transforms since they aren't affected*


Discussion:
This seems to be an issue here: https://github.com/kornia/kornia/blob/master/kornia/augmentation/_2d/geometric/center_crop.py#L99

are you open to send a pr to fix ?

BTW, we recently included our `kornia.io` api — https://kornia.readthedocs.io/en/latest/io.html
Feedback for improvement is very welcomed :)
I will try to do a PR this week

Resolving patch:
diff --git a/kornia/augmentation/_2d/geometric/center_crop.py b/kornia/augmentation/_2d/geometric/center_crop.py
--- a/kornia/augmentation/_2d/geometric/center_crop.py
+++ b/kornia/augmentation/_2d/geometric/center_crop.py
@@ -91,12 +91,10 @@ def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, Tensor]:
         return rg.center_crop_generator(batch_shape[0], batch_shape[-2], batch_shape[-1], self.size, self.device)
 
     def compute_transformation(self, input: Tensor, params: Dict[str, Tensor], flags: Dict[str, Any]) -> Tensor:
-        if flags["cropping_mode"] == "resample":
+        if flags["cropping_mode"] in ("resample", "slice"):
             transform: Tensor = get_perspective_transform(params["src"].to(input), params["dst"].to(input))
             transform = transform.expand(input.shape[0], -1, -1)
             return transform
-        if flags["cropping_mode"] == "slice":  # Skip the computation for slicing.
-            return self.identity_matrix(input)
         raise NotImplementedError(f"Not supported type: {flags['cropping_mode']}.")
 
     def apply_transform(
diff --git a/kornia/augmentation/_2d/geometric/crop.py b/kornia/augmentation/_2d/geometric/crop.py
--- a/kornia/augmentation/_2d/geometric/crop.py
+++ b/kornia/augmentation/_2d/geometric/crop.py
@@ -148,11 +148,9 @@ def precrop_padding(
         return input
 
     def compute_transformation(self, input: Tensor, params: Dict[str, Tensor], flags: Dict[str, Any]) -> Tensor:
-        if flags["cropping_mode"] == "resample":
+        if flags["cropping_mode"] in ("resample", "slice"):
             transform: Tensor = get_perspective_transform(params["src"].to(input), params["dst"].to(input))
             return transform
-        if flags["cropping_mode"] == "slice":  # Skip the computation for slicing.
-            return self.identity_matrix(input)
         raise NotImplementedError(f"Not supported type: {flags['cropping_mode']}.")
 
     def apply_transform(
diff --git a/kornia/augmentation/_2d/geometric/resized_crop.py b/kornia/augmentation/_2d/geometric/resized_crop.py
--- a/kornia/augmentation/_2d/geometric/resized_crop.py
+++ b/kornia/augmentation/_2d/geometric/resized_crop.py
@@ -87,12 +87,10 @@ def __init__(
         )
 
     def compute_transformation(self, input: Tensor, params: Dict[str, Tensor], flags: Dict[str, Any]) -> Tensor:
-        if flags["cropping_mode"] == "resample":
+        if flags["cropping_mode"] in ("resample", "slice"):
             transform: Tensor = get_perspective_transform(params["src"].to(input), params["dst"].to(input))
             transform = transform.expand(input.shape[0], -1, -1)
             return transform
-        if flags["cropping_mode"] == "slice":  # Skip the computation for slicing.
-            return self.identity_matrix(input)
         raise NotImplementedError(f"Not supported type: {flags['cropping_mode']}.")
 
     def apply_transform(


Test patch: