Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Augmentation documentation update (#730)

shijianjian0820e09e4310
diff --git a/docs/source/augmentation.rst b/docs/source/augmentation.rst
index e31d852cb..29a074688 100644
--- a/docs/source/augmentation.rst
+++ b/docs/source/augmentation.rst
@@ -168,6 +168,7 @@ Set of operators to perform data augmentation on 3D image tensors and volumetric
.. autoclass:: RandomAffine3D
.. autoclass:: RandomCrop3D
.. autoclass:: CenterCrop3D
+.. autoclass:: RandomMotionBlur3D
.. autoclass:: RandomEqualize3D
Functional
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index f99477a82..73f7d089f 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -40,6 +40,15 @@ class RandomHorizontalFlip(AugmentationBase2D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> input = torch.tensor([[[[0., 0., 0.],
... [0., 0., 0.],
@@ -71,12 +80,6 @@ class RandomVerticalFlip(AugmentationBase2D):
r"""Applies a random vertical flip to a tensor image or a batch of tensor images with a given probability.
- Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
- If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
- the corresponding transformation matrix that has been applied to them. In this case the module
- will Vertically flip the tensors and concatenate the corresponding transformation matrix to the
- previous one. This is especially useful when using this functionality as part of an ``nn.Sequential`` module.
-
Args:
p (float): probability of the image being flipped. Default value is 0.5
return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
@@ -84,6 +87,15 @@ class RandomVerticalFlip(AugmentationBase2D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> input = torch.tensor([[[[0., 0., 0.],
... [0., 0., 0.],
@@ -115,8 +127,6 @@ class ColorJitter(AugmentationBase2D):
r"""Applies a random transformation to the brightness, contrast, saturation and hue of a tensor image.
- Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
-
Args:
p (float): probability of applying the transformation. Default value is 1.
brightness (float or tuple): Default value is 0.
@@ -128,6 +138,15 @@ class ColorJitter(AugmentationBase2D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.ones(1, 3, 3, 3)
@@ -184,6 +203,15 @@ class RandomGrayscale(AugmentationBase2D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.randn((1, 3, 3, 3))
@@ -234,6 +262,15 @@ class RandomErasing(AugmentationBase2D):
ratio (Tuple[float, float]): range of aspect ratio of erased area.
same_on_batch (bool): apply the same transformation across the batch. Default: False
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.ones(1, 1, 3, 3)
@@ -283,6 +320,15 @@ class RandomPerspective(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs= torch.tensor([[[[1., 0., 0.],
@@ -365,6 +411,15 @@ class RandomAffine(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 3, 3)
@@ -443,12 +498,21 @@ class CenterCrop(AugmentationBase2D):
Args:
p (float): probability of applying the transformation for the whole batch. Default value is 1.
- size (sequence or int): Desired output size of the crop. If size is an
- int instead of sequence like (h, w), a square crop (size, size) is
- made.
+ size (Tuple[int, int] or int): Desired output size (out_h, out_w) of the crop.
+ If integer, out_h = out_w = size.
+ If Tuple[int, int], out_h = size[0], out_w = size[1].
return_transform (bool): if ``True`` return the matrix describing the transformation
applied to each. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, out_h, out_w)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.randn(1, 1, 3, 3)
@@ -498,12 +562,6 @@ class CenterCrop(AugmentationBase2D):
class RandomRotation(AugmentationBase2D):
r"""Applies a random rotation to a tensor image or a batch of tensor images given an amount of degrees.
- Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
- If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
- the corresponding transformation matrix that has been applied to them. In this case the module
- will rotate the tensors and concatenate the corresponding transformation matrix to the
- previous one. This is especially useful when using this functionality as part of an ``nn.Sequential`` module.
-
Args:
p (float): probability of applying the transformation. Default value is 0.5.
degrees (sequence or float or tensor): range of degrees to select from. If degrees is a number the
@@ -515,6 +573,15 @@ class RandomRotation(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.tensor([[1., 0., 0., 2.],
@@ -572,7 +639,8 @@ class RandomCrop(AugmentationBase2D):
Args:
p (float): probability of applying the transformation for the whole batch. Default value is 1.0.
- size (tuple): Desired output size of the crop, like (h, w).
+ size (Tuple[int, int]): Desired output size (out_h, out_w) of the crop.
+ Must be Tuple[int, int], then out_h = size[0], out_w = size[1].
padding (int or sequence, optional): Optional padding on each border
of the image. Default is None, i.e no padding. If a sequence of length
4 is provided, it is used to pad left, top, right, bottom borders
@@ -592,6 +660,15 @@ class RandomCrop(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, out_h, out_w)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.randn(1, 1, 3, 3)
@@ -676,7 +753,8 @@ class RandomResizedCrop(AugmentationBase2D):
r"""Crops random patches in an image tensor and resizes to a given size.
Args:
- size (Tuple[int, int]): expected output size of each edge.
+ size (Tuple[int, int]): Desired output size (out_h, out_w) of each edge.
+ Must be Tuple[int, int], then out_h = size[0], out_w = size[1].
scale: range of size of the origin size cropped.
ratio: range of aspect ratio of the origin aspect ratio cropped.
resample (int, str or kornia.Resample): Default: Resample.BILINEAR.
@@ -686,6 +764,15 @@ class RandomResizedCrop(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
+ - Output: :math:`(B, C, out_h, out_w)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Example:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.tensor([[[0., 1., 2.],
@@ -761,9 +848,14 @@ class RandomMotionBlur(AugmentationBase2D):
CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.
Shape:
- - Input: :math:`(B, C, H, W)`
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
- Output: :math:`(B, C, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 5, 5)
@@ -827,10 +919,16 @@ class RandomSolarize(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
input tensor. If ``False`` and the input is a tuple the applied transformation wont be concatenated.
+
Shape:
- - Input: :math:`(B, C, H, W)`
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
- Output: :math:`(B, C, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 5, 5)
@@ -886,9 +984,14 @@ class RandomPosterize(AugmentationBase2D):
input tensor. If ``False`` and the input is a tuple the applied transformation wont be concatenated.
Shape:
- - Input: :math:`(B, C, H, W)`
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
- Output: :math:`(B, C, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 5, 5)
@@ -937,10 +1040,16 @@ class RandomSharpness(AugmentationBase2D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
input tensor. If ``False`` and the input is a tuple the applied transformation wont be concatenated.
+
Shape:
- - Input: :math:`(B, C, H, W)`
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
- Output: :math:`(B, C, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 5, 5)
@@ -1001,10 +1110,16 @@ class RandomEqualize(AugmentationBase2D):
return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
input tensor. If ``False`` and the input is a tuple the applied transformation
wont be concatenated
+
Shape:
- - Input: :math:`(B, C, H, W)`
+ - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
- Output: :math:`(B, C, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 3, 3)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 5, 5)
diff --git a/kornia/augmentation/augmentation3d.py b/kornia/augmentation/augmentation3d.py
index ff2d47903..d49f8e39e 100644
--- a/kornia/augmentation/augmentation3d.py
+++ b/kornia/augmentation/augmentation3d.py
@@ -15,13 +15,7 @@ from .utils import (
class RandomHorizontalFlip3D(AugmentationBase3D):
- r"""Applies a random horizontal flip to a 3D image tensor with a given probability.
-
- Input should be a tensor of shape :math:`(C, D, H, W)` or a batch of tensors :math:`(*, C, D, H, W)`.
- If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
- the corresponding transformation matrix that has been applied to them. In this case the module
- will Horizontally flip the tensors and concatenate the corresponding transformation matrix to the
- previous one. This is especially useful when using this functionality as part of an ``nn.Sequential`` module.
+ r"""Apply random horizontal flip to 3D volumes (5D tensor).
Args:
p (float): probability of the image being flipped. Default value is 0.5.
@@ -30,6 +24,15 @@ class RandomHorizontalFlip3D(AugmentationBase3D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> x = torch.eye(3).repeat(3, 1, 1)
>>> seq = RandomHorizontalFlip3D(p=1.0, return_transform=True)
@@ -48,7 +51,6 @@ class RandomHorizontalFlip3D(AugmentationBase3D):
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]]]))
-
"""
def __init__(self, return_transform: bool = False, same_on_batch: bool = False, p: float = 0.5) -> None:
@@ -69,7 +71,7 @@ class RandomHorizontalFlip3D(AugmentationBase3D):
class RandomVerticalFlip3D(AugmentationBase3D):
- r"""Applies a random vertical flip to a 3D image tensor with a given probability.
+ r"""Apply random vertical flip to 3D volumes (5D tensor).
Input should be a tensor of shape :math:`(C, D, H, W)` or a batch of tensors :math:`(*, C, D, H, W)`.
If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
@@ -84,6 +86,15 @@ class RandomVerticalFlip3D(AugmentationBase3D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> x = torch.eye(3).repeat(3, 1, 1)
>>> seq = RandomVerticalFlip3D(p=1.0, return_transform=True)
@@ -122,7 +133,7 @@ class RandomVerticalFlip3D(AugmentationBase3D):
class RandomDepthicalFlip3D(AugmentationBase3D):
- r"""Applies a random flip along the depth axis of a 3D image tensor with a given probability.
+ r"""Apply random flip along the depth axis of 3D volumes (5D tensor).
Input should be a tensor of shape :math:`(C, D, H, W)` or a batch of tensors :math:`(*, C, D, H, W)`.
If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
@@ -137,6 +148,15 @@ class RandomDepthicalFlip3D(AugmentationBase3D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> x = torch.eye(3).repeat(3, 1, 1)
>>> seq = RandomDepthicalFlip3D(p=1.0, return_transform=True)
@@ -176,7 +196,7 @@ class RandomDepthicalFlip3D(AugmentationBase3D):
class RandomAffine3D(AugmentationBase3D):
- r"""Applies a 3D affine transformation to a 3D image tensor with a given probability.
+ r"""Apply affine transformation 3D volumes (5D tensor).
The transformation is computed so that the center is kept invariant.
@@ -212,6 +232,15 @@ class RandomAffine3D(AugmentationBase3D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 3, 3, 3)
@@ -295,7 +324,7 @@ class RandomAffine3D(AugmentationBase3D):
class RandomRotation3D(AugmentationBase3D):
- r"""Applies a random rotation to a 3D tensor image or a batch of tensor images given an amount of degrees.
+ r"""Apply random rotations to 3D volumes (5D tensor).
Input should be a tensor of shape (C, D, H, W) or a batch of tensors :math:`(B, C, D, H, W)`.
If Input is a tuple it is assumed that the first element contains the aforementioned tensors and the second,
@@ -319,6 +348,15 @@ class RandomRotation3D(AugmentationBase3D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 3, 3, 3)
@@ -376,7 +414,7 @@ class RandomRotation3D(AugmentationBase3D):
class RandomMotionBlur3D(AugmentationBase3D):
- r"""Perform motion blur on 3D volumes (5D tensor).
+ r"""Apply random motion blur on 3D volumes (5D tensor).
Args:
p (float): probability of applying the transformation. Default value is 0.5.
@@ -401,9 +439,14 @@ class RandomMotionBlur3D(AugmentationBase3D):
CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.
Shape:
- - Input: :math:`(B, C, D, H, W)`
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
- Output: :math:`(B, C, D, H, W)`
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 3, 5, 5)
@@ -430,7 +473,8 @@ class RandomMotionBlur3D(AugmentationBase3D):
def __init__(
self, kernel_size: Union[int, Tuple[int, int]],
- angle: Union[torch.Tensor, float, Tuple[float, float]],
+ angle: Union[torch.Tensor, float, Tuple[float, float, float],
+ Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]],
direction: Union[torch.Tensor, float, Tuple[float, float]],
border_type: Union[int, str, BorderType] = BorderType.CONSTANT.name,
return_transform: bool = False, same_on_batch: bool = False, p: float = 0.5
@@ -466,19 +510,28 @@ class RandomMotionBlur3D(AugmentationBase3D):
class CenterCrop3D(AugmentationBase3D):
- r"""Crops a given image tensor at the center.
+ r"""Apply center crop on 3D volumes (5D tensor).
Args:
p (float): probability of applying the transformation for the whole batch. Default value is 1.
- size (sequence or int): Desired output size of the crop. If size is an
- int instead of sequence like (d, h, w), a square crop (size, size, size) is
- made.
+ size (Tuple[int, int, int] or int): Desired output size (out_d, out_h, out_w) of the crop.
+ If integer, out_d = out_h = out_w = size.
+ If Tuple[int, int, int], out_d = size[0], out_h = size[1], out_w = size[2].
resample (int, str or kornia.Resample): Default: Resample.BILINEAR
return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
input tensor. If ``False`` and the input is a tuple the applied transformation
wont be concatenated.
align_corners(bool): interpolation flag. Default: True.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, out_d, out_h, out_w)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.randn(1, 1, 3, 3, 3)
@@ -528,11 +581,14 @@ class CenterCrop3D(AugmentationBase3D):
class RandomCrop3D(AugmentationBase3D):
- r"""Crops random patches of a tensor image on a given size.
+ r"""Apply random crop on 3D volumes (5D tensor).
+
+ Crops random sub-volumes on a given size.
Args:
p (float): probability of applying the transformation for the whole batch. Default value is 1.0.
- size (tuple): Desired output size of the crop, like (d, h, w).
+ size (Tuple[int, int, int]): Desired output size (out_d, out_h, out_w) of the crop.
+ Must be Tuple[int, int, int], then out_d = size[0], out_h = size[1], out_w = size[2].
padding (int or sequence, optional): Optional padding on each border of the image.
Default is None, i.e no padding. If a sequence of length 6 is provided, it is used to pad
left, top, right, bottom, front, back borders respectively.
@@ -552,6 +608,15 @@ class RandomCrop3D(AugmentationBase3D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: True.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, , out_d, out_h, out_w)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs = torch.randn(1, 1, 3, 3, 3)
@@ -647,7 +712,7 @@ class RandomCrop3D(AugmentationBase3D):
class RandomPerspective3D(AugmentationBase3D):
- r"""Applies a random perspective transformation to an image tensor with a given probability.
+ r"""Apply andom perspective transformation to 3D volumes (5D tensor).
Args:
p (float): probability of the image being perspectively transformed. Default value is 0.5.
@@ -658,6 +723,15 @@ class RandomPerspective3D(AugmentationBase3D):
same_on_batch (bool): apply the same transformation across the batch. Default: False.
align_corners(bool): interpolation flag. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> inputs= torch.tensor([[[
@@ -720,7 +794,7 @@ class RandomPerspective3D(AugmentationBase3D):
class RandomEqualize3D(AugmentationBase3D):
- r"""Random 3D equalization of a volumetric image.
+ r"""Apply random equalization to 3D volumes (5D tensor).
Args:
p (float): probability of the image being equalized. Default value is 0.5.
@@ -730,6 +804,15 @@ class RandomEqualize3D(AugmentationBase3D):
wont be concatenated.
same_on_batch (bool): apply the same transformation across the batch. Default: False.
+ Shape:
+ - Input: :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)`, Optional: :math:`(B, 4, 4)`
+ - Output: :math:`(B, C, D, H, W)`
+
+ Note:
+ Input tensor must be float and normalized into [0, 1] for the best differentiability support.
+ Additionally, this function accepts another transformation tensor (:math:`(B, 4, 4)`), then the
+ applied transformation will be merged int to the input transformation tensor and returned.
+
Examples:
>>> rng = torch.manual_seed(0)
>>> input = torch.rand(1, 1, 3, 3, 3)
diff --git a/kornia/augmentation/functional/__temp__.py b/kornia/augmentation/functional/__temp__.py
index 4c7262fa2..206bfff65 100644
--- a/kornia/augmentation/functional/__temp__.py
+++ b/kornia/augmentation/functional/__temp__.py
@@ -3,4 +3,4 @@ import warnings
def __deprecation_warning(name: str, replacement: str):
warnings.warn(f"`{name}` is no longer maintained and will be removed from the future versions. "
- f"Please use {replacement} instead.")
+ f"Please use {replacement} instead.", category=DeprecationWarning)