Repository: kornia/kornia

Issue:
Exposing `padding_mode` in elastic transforms.
## 🚀 Feature
<!-- A clear and concise description of the feature proposal -->
Exposing `padding_mode` in `RandomElasticTransform` and `elastic_transform2d`.
## Motivation
<!-- Please outline the motivation for the proposal. Is your feature request related to a problem? e.g., I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too -->
 In `F.grid_sample` as used in kornia's elastic transforms, the default setting `padding_mode = 'zeros'` leaves unnatural black artifacts in the newly created borders of transformed images. 
## Pitch
<!-- A clear and concise description of what you want to happen. -->
Exposure of `padding_mode` in elastic transform functions/classes (as it seems has been done for affine warping functions/classes https://github.com/kornia/kornia/pull/640) would allow for selection of more natural settings like 'reflection'.

Thanks and outstanding work!



Discussion:
Can you send a PR to expose this? Let us know if any difficulties.

Resolving patch:
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -2146,6 +2146,8 @@ class RandomElasticTransform(GeometricAugmentationBase2D):
           in the y and x directions, respectively.
         align_corners: Interpolation flag used by `grid_sample`.
         mode: Interpolation mode used by `grid_sample`. Either 'bilinear' or 'nearest'.
+        padding_mode: The padding used by ```grid_sample```. Either 'zeros', 'border' or 'refection'.
+
         return_transform: if ``True`` return the matrix describing the transformation applied to each
             input tensor. If ``False`` and the input is a tuple the applied transformation won't be concatenated.
         same_on_batch: apply the same transformation across the batch.
@@ -2168,6 +2170,7 @@ def __init__(
         alpha: Tuple[float, float] = (1.0, 1.0),
         align_corners: bool = False,
         mode: str = 'bilinear',
+        padding_mode: str = 'zeros',
         return_transform: bool = False,
         same_on_batch: bool = False,
         p: float = 0.5,
@@ -2178,6 +2181,7 @@ def __init__(
         self.alpha = alpha
         self.align_corners = align_corners
         self.mode = mode
+        self.padding_mode = padding_mode
 
     def __repr__(self) -> str:
         return self.__class__.__name__ + f"({super().__repr__()})"
@@ -2198,7 +2202,8 @@ def apply_transform(
         self, input: torch.Tensor, params: Dict[str, torch.Tensor], transform: Optional[torch.Tensor] = None
     ) -> torch.Tensor:
         return elastic_transform2d(
-            input, params['noise'].to(input), self.kernel_size, self.sigma, self.alpha, self.align_corners, self.mode
+            input, params['noise'].to(input), self.kernel_size, self.sigma, self.alpha, self.align_corners, self.mode,
+            self.padding_mode
         )
 
 
diff --git a/kornia/geometry/transform/elastic_transform.py b/kornia/geometry/transform/elastic_transform.py
--- a/kornia/geometry/transform/elastic_transform.py
+++ b/kornia/geometry/transform/elastic_transform.py
@@ -17,6 +17,7 @@ def elastic_transform2d(
     alpha: Tuple[float, float] = (1.0, 1.0),
     align_corners: bool = False,
     mode: str = 'bilinear',
+    padding_mode: str = 'zeros'
 ) -> torch.Tensor:
     r"""Apply elastic transform of images as described in :cite:`Simard2003BestPF`.
 
@@ -34,6 +35,7 @@ def elastic_transform2d(
           in the y and x directions, respectively.
         align_corners: Interpolation flag used by ```grid_sample```.
         mode: Interpolation mode used by ```grid_sample```. Either ``'bilinear'`` or ``'nearest'``.
+        padding_mode: The padding used by ```grid_sample```. Either ``'zeros'``, ``'border'`` or ``'refection'``.
 
     .. note:
         ```sigma``` and ```alpha``` can also be a ``torch.Tensor``. However, you could not torchscript
@@ -89,6 +91,7 @@ def elastic_transform2d(
     # Warp image based on displacement matrix
     _, _, h, w = image.shape
     grid = create_meshgrid(h, w, device=image.device).to(image.dtype)
-    warped = F.grid_sample(image, (grid + disp).clamp(-1, 1), align_corners=align_corners, mode=mode)
+    warped = F.grid_sample(image, (grid + disp).clamp(-1, 1), align_corners=align_corners, mode=mode,
+                           padding_mode=padding_mode)
 
     return warped


Test patch: