Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Refined docs for augmentation and functional. (#922)

shijianjianb1e9f802e213
diff --git a/docs/source/augmentation.module.rst b/docs/source/augmentation.module.rst
index fdc97da38..ca824b514 100644
--- a/docs/source/augmentation.module.rst
+++ b/docs/source/augmentation.module.rst
@@ -30,6 +30,8 @@ Set of operators to perform data augmentation on 2D image tensors.
:members:
+.. currentmodule:: kornia.augmentation
+
Transforms3D
============
@@ -49,6 +51,8 @@ Set of operators to perform data augmentation on 3D volumetric tensors.
:members:
+.. currentmodule:: kornia.augmentation
+
Normalizations
==============
diff --git a/kornia/augmentation/functional/functional.py b/kornia/augmentation/functional/functional.py
index 9827a41df..d5bc1eeec 100644
--- a/kornia/augmentation/functional/functional.py
+++ b/kornia/augmentation/functional/functional.py
@@ -255,10 +255,10 @@ def apply_hflip(input: torch.Tensor) -> torch.Tensor:
Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The horizontally flipped input
+ torch.Tensor: The horizontally flipped input with shape :math:`(*, C, H, W)`.
"""
return hflip(input)
@@ -266,15 +266,14 @@ def apply_hflip(input: torch.Tensor) -> torch.Tensor:
@_validate_input
def compute_hflip_transformation(input: torch.Tensor) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the horizontal flip transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`
+ torch.Tensor: The horizontal flip transformation matrix :math: `(*, 3, 3)`
"""
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
w: int = input.shape[-1]
flip_mat: torch.Tensor = torch.tensor([[-1, 0, w - 1],
@@ -288,13 +287,11 @@ def compute_hflip_transformation(input: torch.Tensor) -> torch.Tensor:
def apply_vflip(input: torch.Tensor) -> torch.Tensor:
r"""Apply vertically flip on a tensor image or a batch of tensor images with given random parameters.
- Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).\
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The vertically flipped input
+ torch.Tensor: Vertically flipped input with shape :math:`(B, C, H, W)`.
"""
return vflip(input)
@@ -302,15 +299,14 @@ def apply_vflip(input: torch.Tensor) -> torch.Tensor:
@_validate_input
def compute_vflip_transformation(input: torch.Tensor) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the vertical flip transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`
+ torch.Tensor: The vertical flip transformation matrix :math: `(*, 3, 3)`
"""
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
h: int = input.shape[-2]
flip_mat: torch.Tensor = torch.tensor([[1, 0, 0],
@@ -326,10 +322,8 @@ def apply_color_jitter(
) -> torch.Tensor:
r"""Apply Color Jitter on a tensor image or a batch of tensor images with given random parameters.
- Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['brightness_factor']: The brightness factor.
- params['contrast_factor']: The contrast factor.
@@ -339,9 +333,8 @@ def apply_color_jitter(
0 is brightness, 1 is contrast, 2 is saturation, 4 is hue.
Returns:
- torch.Tensor: The color jitterred input
+ torch.Tensor: Color jitterred input with shape :math:`(B, C, H, W)`.
"""
- # TODO: params validation
transforms = [
lambda img: apply_adjust_brightness(img, params),
@@ -360,13 +353,13 @@ def apply_color_jitter(
@_validate_input
def compute_intensity_transformation(input: torch.Tensor):
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the identity matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`. Returns identity transformations.
+ torch.Tensor: The applied matrix :math: `(*, 3, 3)`.
"""
identity: torch.Tensor = torch.eye(3, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)
return identity
@@ -376,13 +369,11 @@ def compute_intensity_transformation(input: torch.Tensor):
def apply_grayscale(input: torch.Tensor) -> torch.Tensor:
r"""Apply Gray Scale on a tensor image or a batch of tensor images with given random parameters.
- Input should be a tensor of shape (3, H, W) or a batch of tensors :math:`(*, 3, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: The grayscaled input
+ torch.Tensor: The grayscaled input with shape :math:`(B, C, H, W)`.
"""
if not _validate_input_shape(input, 1, 3):
raise ValueError(f"Input size must have a shape of (*, 3, H, W). Got {input.shape}")
@@ -402,7 +393,7 @@ def apply_perspective(
r"""Perform perspective transform of the given torch.Tensor or batch of tensors.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['start_points']: Tensor containing [top-left, top-right, bottom-right,
bottom-left] of the original image with shape Bx4x2.
@@ -436,10 +427,10 @@ def apply_perspective(
@_validate_input
def compute_perspective_transformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the perspective transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['start_points']: Tensor containing [top-left, top-right, bottom-right,
bottom-left] of the orignal image with shape Bx4x2.
@@ -447,7 +438,7 @@ def compute_perspective_transformation(input: torch.Tensor, params: Dict[str, to
bottom-left] of the transformed image with shape Bx4x2.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`
+ torch.Tensor: The perspective transformation matrix :math: `(*, 3, 3)`
"""
perspective_transform: torch.Tensor = get_perspective_transform(
params['start_points'], params['end_points']).type_as(input)
@@ -464,7 +455,7 @@ def apply_affine(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Di
r"""Random affine transformation of the image keeping center invariant.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['angle']: Degrees of rotation.
- params['translations']: Horizontal and vertical translations.
@@ -478,7 +469,7 @@ def apply_affine(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Di
- params['align_corners']: Boolean tensor.
Returns:
- torch.Tensor: The transfromed input
+ torch.Tensor: The transfromed input with shape :math:`(B, C, H, W)`.
"""
# arrange input data
x_data: torch.Tensor = input.view(-1, *input.shape[-3:])
@@ -501,10 +492,10 @@ def apply_affine(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Di
@_validate_input
def compute_affine_transformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the affine transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['angle']: Degrees of rotation.
- params['translations']: Horizontal and vertical translations.
@@ -514,7 +505,7 @@ def compute_affine_transformation(input: torch.Tensor, params: Dict[str, torch.T
- params['sy']: Shear param toward y-axis.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`
+ torch.Tensor: The affine transformation matrix :math: `(*, 3, 3)`.
"""
transform = get_affine_matrix2d(
params['translations'], params['center'], params['scale'], params['angle'],
@@ -529,10 +520,8 @@ def apply_rotation(
) -> torch.Tensor:
r"""Rotate a tensor image or a batch of tensor images a random amount of degrees.
- Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['degrees']: degree to be applied.
flags (Dict[str, torch.Tensor]):
@@ -540,7 +529,7 @@ def apply_rotation(
- params['align_corners']: Boolean tensor.
Returns:
- torch.Tensor: The cropped input
+ torch.Tensor: The cropped input.
"""
angles: torch.Tensor = params["degrees"].type_as(input)
@@ -554,15 +543,15 @@ def apply_rotation(
@_validate_input
def compute_rotate_tranformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
+ r"""Compute the rotation transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['degrees']: degree to be applied.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`
+ torch.Tensor: The rotation transformation matrix :math: `(*, 3, 3)`
"""
angles: torch.Tensor = params["degrees"].type_as(input)
@@ -585,7 +574,7 @@ def apply_crop(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict
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).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, 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)`.
@@ -608,7 +597,7 @@ def compute_crop_transformation(input: torch.Tensor, params: Dict[str, torch.Ten
r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, 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)`.
@@ -625,10 +614,10 @@ def compute_crop_transformation(input: torch.Tensor, params: Dict[str, torch.Ten
def apply_erase_rectangles(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Apply rectangle erase by params.
- Generate a {0, 1} mask with drawed rectangle having parameters defined by params and size by input.size()
+ Generate a {0, 1} mask with drawed rectangle having parameters defined by params and size by input.size().
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['widths']: widths tensor
- params['heights']: heights tensor
@@ -637,7 +626,7 @@ def apply_erase_rectangles(input: torch.Tensor, params: Dict[str, torch.Tensor])
- params['values']: the value to fill in
Returns:
- torch.Tensor: Erased image.
+ torch.Tensor: Erased image with shape :math:`(B, C, H, W)`.
"""
if not (params['widths'].size() == params['heights'].size() == params['xs'].size() == params['ys'].size()):
raise TypeError(
@@ -664,14 +653,14 @@ def apply_adjust_brightness(input: torch.Tensor, params: Dict[str, torch.Tensor]
Wrapper for adjust_brightness for Torchvision-like param settings.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['brightness_factor']: Brightness adjust factor per element
in the batch. 0 gives a black image, 1 does not modify the input image and 2 gives a
white image, while any other number modify the brightness.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
transformed = adjust_brightness(input, params['brightness_factor'].to(input.dtype) - 1)
@@ -685,14 +674,14 @@ def apply_adjust_contrast(input: torch.Tensor, params: Dict[str, torch.Tensor])
Wrapper for adjust_contrast for Torchvision-like param settings.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['contrast_factor']: Contrast adjust factor per element in the batch.
0 generates a compleatly black image, 1 does not modify the input image while any other
non-negative number modify the brightness by this factor.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
transformed = adjust_contrast(input, params['contrast_factor'].to(input.dtype))
@@ -706,14 +695,14 @@ def apply_adjust_saturation(input: torch.Tensor, params: Dict[str, torch.Tensor]
Wrapper for adjust_saturation for Torchvision-like param settings.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['saturation_factor']: How much to adjust the saturation. 0 will give a black
and white image, 1 will give the original image while 2 will enhance the saturation
by a factor of 2.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
transformed = adjust_saturation(input, params['saturation_factor'].to(input.dtype))
@@ -727,7 +716,7 @@ def apply_adjust_hue(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> to
Wrapper for adjust_hue for Torchvision-like param settings.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['hue_factor']: How much to shift the hue channel. Should be in [-0.5, 0.5].
0.5 and -0.5 give complete reversal of hue channel in HSV space in positive and negative
@@ -735,7 +724,7 @@ def apply_adjust_hue(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> to
image with complementary colors while 0 gives the original image.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
transformed = adjust_hue(input, params['hue_factor'].to(input.dtype) * 2 * pi)
@@ -747,14 +736,14 @@ def apply_adjust_gamma(input: torch.Tensor, params: Dict[str, torch.Tensor]) ->
r"""Perform gamma correction on an image.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['gamma_factor']: Non negative real number, same as γ\gammaγ in the equation.
gamma larger than 1 make the shadows darker, while gamma smaller than 1 make
dark regions lighter.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
transformed = adjust_gamma(input, params['gamma_factor'].to(input.dtype))
@@ -766,10 +755,8 @@ def apply_motion_blur(input: torch.Tensor, params: Dict[str, torch.Tensor],
flags: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Perform motion blur on an image.
- The input image is expected to be in the range of [0, 1].
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['ksize_factor']: motion kernel width and height (odd and positive).
- params['angle_factor']: angle of the motion blur in degrees (anti-clockwise rotation).
@@ -782,7 +769,7 @@ def apply_motion_blur(input: torch.Tensor, params: Dict[str, torch.Tensor],
CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.
Returns:
- torch.Tensor: Adjusted image with the shape as the input (\*, C, H, W).
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
kernel_size: int = cast(int, params['ksize_factor'].unique().item())
@@ -799,13 +786,13 @@ def apply_solarize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torc
r"""Solarize an image.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['thresholds_factor']: thresholds ranged from 0 ~ 1.
- params['additions_factor']: additions to add on before solarizing.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
thresholds = params['thresholds_factor']
additions: Optional[torch.Tensor]
@@ -821,12 +808,12 @@ def apply_posterize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> tor
r"""Posterize an image.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['bits_factor']: uint8 bits number ranged from 0 to 8.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
bits = params['bits_factor']
@@ -838,12 +825,12 @@ def apply_sharpness(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> tor
r"""Sharpen an image.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
params (Dict[str, torch.Tensor]):
- params['sharpness_factor']: Sharpness strength. Must be above 0.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
factor = params['sharpness_factor']
@@ -855,10 +842,10 @@ def apply_equalize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torc
r"""Equalize an image.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
Returns:
- torch.Tensor: Adjusted image.
+ torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.
"""
return equalize(input)
@@ -871,8 +858,8 @@ def apply_mixup(input: torch.Tensor, labels: torch.Tensor,
MixUp augmentation strategy: overlap images with different alpha values.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
- labels (torch.Tensor): Label tensor with shape (B,).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
+ labels (torch.Tensor): Label tensor with shape :math:`(B,)`.
params (Dict[str, torch.Tensor]):
- params['mixup_pairs']: Mixup indexes.
- params['mixup_lambdas']: Lambda for the mixup strength.
@@ -924,11 +911,11 @@ def apply_cutmix(input: torch.Tensor, labels: torch.Tensor,
truth labels are also mixed proportionally to the area of the patches.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
- labels (torch.Tensor): Label tensor with shape (B,).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.
+ labels (torch.Tensor): Label tensor with shape :math:`(B,)`.
params (Dict[str, torch.Tensor]):
- - params['mix_pairs']: Mixup indexes with shape (num_mixes, B).
- - params['crop_src']: Lambda for the mixup strength (num_mixes, B, 4, 2).
+ - params['mix_pairs']: Mixup indexes with shape :math:`(num_mixes, B)`.
+ - params['crop_src']: Lambda for the mixup strength :math:`(num_mixes, B, 4, 2)`.
Returns:
Tuple[torch.Tensor, torch.Tensor]:
diff --git a/kornia/augmentation/functional/functional3d.py b/kornia/augmentation/functional/functional3d.py
index 4fcfb5afc..5e1c944ad 100644
--- a/kornia/augmentation/functional/functional3d.py
+++ b/kornia/augmentation/functional/functional3d.py
@@ -22,8 +22,7 @@ from kornia.enhance import (
from .. import random_generator as rg
from ..utils import (
- _transform_input3d,
- _validate_input_dtype
+ _validate_input3d
)
from kornia.filters import motion_blur3d
@@ -87,36 +86,30 @@ def random_dflip3d(input: torch.Tensor, p: float = 0.5, return_transform: bool =
return output
+@_validate_input3d
def apply_hflip3d(input: torch.Tensor) -> torch.Tensor:
r"""Apply horizontal flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.
- Input should be a tensor of shape :math:`(D, H, W)`, :math:`(C, D, H, W)` or :math:`(*, C, D, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The horizontal flipped input
+ torch.Tensor: Horizontal flipped input with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
return torch.flip(input, [-1])
+@_validate_input3d
def compute_hflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the horizontal flip transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: Horizontal flip transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
w: int = input.shape[-1]
flip_mat: torch.Tensor = torch.tensor([[-1, 0, 0, w - 1],
@@ -124,39 +117,33 @@ def compute_hflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
[0, 0, 1, 0],
[0, 0, 0, 1]])
- return flip_mat.repeat(input.size(0), 1, 1).type_as(input)
+ return flip_mat.repeat(input.size(0), 1, 1).to(input)
+@_validate_input3d
def apply_vflip3d(input: torch.Tensor) -> torch.Tensor:
r"""Apply vertical flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.
- Input should be a tensor of shape :math:`(D, H, W)`, :math:`(C, D, H, W)` or :math:`(*, C, D, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The vertical flipped input
+ torch.Tensor: Vertical flipped input with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
return torch.flip(input, [-2])
+@_validate_input3d
def compute_vflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the veritical flip transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: The vertical flip transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
h: int = input.shape[-2]
flip_mat: torch.Tensor = torch.tensor([[1, 0, 0, 0],
@@ -164,54 +151,47 @@ def compute_vflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
[0, 0, 1, 0],
[0, 0, 0, 1]])
- return flip_mat.repeat(input.size(0), 1, 1).type_as(input)
+ return flip_mat.repeat(input.size(0), 1, 1).to(input)
+@_validate_input3d
def apply_dflip3d(input: torch.Tensor) -> torch.Tensor:
r"""Apply depthical flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.
- Input should be a tensor of shape :math:`(D, H, W)`, :math:`(C, D, H, W)` or :math:`(*, C, D, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The depthical flipped input.
+ torch.Tensor: Depthical flipped input with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
return torch.flip(input, [-3])
+@_validate_input3d
def compute_intensity_transformation3d(input: torch.Tensor):
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the identity matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`. Returns identity transformations.
+ torch.Tensor: Identity matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
identity: torch.Tensor = torch.eye(4, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)
return identity
+@_validate_input3d
def compute_dflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the depthical flip transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`, :math:`(C, D, H, W)`,
- :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: Depthical flip transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
d: int = input.shape[-3]
flip_mat: torch.Tensor = torch.tensor([[1, 0, 0, 0],
@@ -219,15 +199,16 @@ def compute_dflip_transformation3d(input: torch.Tensor) -> torch.Tensor:
[0, 0, -1, d - 1],
[0, 0, 0, 1]])
- return flip_mat.repeat(input.size(0), 1, 1).type_as(input)
+ return flip_mat.repeat(input.size(0), 1, 1).to(input)
+@_validate_input3d
def apply_affine3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
flags: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Random affine transformation of the image keeping center invariant.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (D, H, W), (C, D, H, W), (B, C, D, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['angles']: Degrees of rotation with the shape of :math: `(*, 3)` for yaw, pitch, roll.
- params['translations']: Horizontal, vertical and depthical translations (dx,dy,dz).
@@ -244,13 +225,8 @@ def apply_affine3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
- params['align_corners']: Boolean tensor.
Returns:
- torch.Tensor: The transfromed input
+ torch.Tensor: Affine transfromed input with shape :math:`(*, C, D, H, W)`.
"""
- if not torch.is_tensor(input):
- raise TypeError(f"Input type is not a torch.Tensor. Got {type(input)}")
-
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
# arrange input data
x_data: torch.Tensor = input.view(-1, *input.shape[-4:])
@@ -269,11 +245,12 @@ def apply_affine3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
return out_data.view_as(input)
+@_validate_input3d
def compute_affine_transformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the affine transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (D, H, W), (C, D, H, W), (B, C, D, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['angles']: Degrees of rotation with the shape of :math: `(*, 3)` for yaw, pitch, roll.
- params['translations']: Horizontal, vertical and depthical translations (dx,dy,dz).
@@ -287,26 +264,23 @@ def compute_affine_transformation3d(input: torch.Tensor, params: Dict[str, torch
- params['szy']: Shear param toward z-y-axis.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: The affine transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
transform = get_affine_matrix3d(
params['translations'], params['center'], params['scale'], params['angles'],
deg2rad(params['sxy']), deg2rad(params['sxz']), deg2rad(params['syx']),
deg2rad(params['syz']), deg2rad(params['szx']), deg2rad(params['szy'])
- ).type_as(input)
+ ).to(input)
return transform
+@_validate_input3d
def apply_rotation3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
flags: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Rotate a tensor image or a batch of tensor images a random amount of degrees.
- Input should be a tensor of shape (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['degrees']: degree to be applied.
flags (Dict[str, torch.Tensor]):
@@ -314,13 +288,11 @@ def apply_rotation3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
- params['align_corners']: Boolean tensor.
Returns:
- torch.Tensor: The cropped input
+ torch.Tensor: The cropped input.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
- yaw: torch.Tensor = params["yaw"].type_as(input)
- pitch: torch.Tensor = params["pitch"].type_as(input)
- roll: torch.Tensor = params["roll"].type_as(input)
+ yaw: torch.Tensor = params["yaw"].to(input)
+ pitch: torch.Tensor = params["pitch"].to(input)
+ roll: torch.Tensor = params["roll"].to(input)
resample_mode: str = Resample(flags['resample'].item()).name.lower()
align_corners: bool = cast(bool, flags['align_corners'].item())
@@ -330,24 +302,23 @@ def apply_rotation3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
return transformed
+@_validate_input3d
def compute_rotate_tranformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]):
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the rotation transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (D, H, W), (C, D, H, W), (B, C, D, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['yaw']: degree to be applied.
- params['pitch']: degree to be applied.
- params['roll']: degree to be applied.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: The rotation transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
- yaw: torch.Tensor = params["yaw"].type_as(input)
- pitch: torch.Tensor = params["pitch"].type_as(input)
- roll: torch.Tensor = params["roll"].type_as(input)
+ yaw: torch.Tensor = params["yaw"].to(input)
+ pitch: torch.Tensor = params["pitch"].to(input)
+ roll: torch.Tensor = params["roll"].to(input)
center: torch.Tensor = _compute_tensor_center3d(input)
rotation_mat: torch.Tensor = _compute_rotation_matrix3d(yaw, pitch, roll, center.expand(yaw.shape[0], -1))
@@ -361,14 +332,13 @@ def compute_rotate_tranformation3d(input: torch.Tensor, params: Dict[str, torch.
return trans_mat
+@_validate_input3d
def apply_motion_blur3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
flags: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Perform motion blur on an image.
- The input image is expected to be in the range of [0, 1].
-
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['ksize_factor']: motion kernel width and height (odd and positive).
- params['angle_factor']: yaw, pitch and roll range of the motion blur in degrees :math:`(B, 3)`.
@@ -381,11 +351,8 @@ def apply_motion_blur3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.
Returns:
- torch.Tensor: Adjusted image with the shape as the inpute (\*, C, H, W).
-
+ torch.Tensor: adjusted image tensor with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
kernel_size: int = cast(int, params['ksize_factor'].unique().item())
angle = params['angle_factor']
@@ -396,11 +363,13 @@ def apply_motion_blur3d(input: torch.Tensor, params: Dict[str, torch.Tensor],
return motion_blur3d(input, kernel_size, angle, direction, border_type, mode)
+@_validate_input3d
def apply_crop3d(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Apply cropping by src bounding box and dst bounding box.
- Order: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,
- back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.
+ Args:
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
+ params (Dict[str, torch.Tensor]):
- params['src']: The applied cropping src matrix :math: `(*, 8, 3)`.
- params['dst']: The applied cropping dst matrix :math: `(*, 8, 3)`.
flags (Dict[str, torch.Tensor]):
@@ -409,9 +378,11 @@ def apply_crop3d(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Di
Returns:
torch.Tensor: The cropped input.
+
+ Note:
+ BBox order: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,
+ back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
resample_mode: str = Resample.get(flags['interpolation'].item()).name.lower() # type: ignore
align_corners: bool = cast(bool, flags['align_corners'].item())
@@ -420,32 +391,34 @@ def apply_crop3d(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Di
input, params['src'], params['dst'], resample_mode, align_corners=align_corners)
-def compute_crop_transformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]):
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+@_validate_input3d
+def compute_crop_transformation3d(
+ input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]
+) -> torch.Tensor:
+ r"""Compute the cropping transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['src']: The applied cropping src matrix :math: `(*, 8, 3)`.
- params['dst']: The applied cropping dst matrix :math: `(*, 8, 3)`.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: The cropping transformation matrix :math: `(*, 4, 4)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
transform: torch.Tensor = get_perspective_transform3d(params['src'].to(input.dtype), params['dst'].to(input.dtype))
- transform = transform.expand(input.shape[0], -1, -1).type_as(input)
+ transform = transform.expand(input.shape[0], -1, -1).to(input)
return transform
+@_validate_input3d
def apply_perspective3d(
input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]
) -> torch.Tensor:
r"""Perform perspective transform of the given torch.Tensor or batch of tensors.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (D, H, W), (C, D, H, W), (B, C, D, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['start_points']: Tensor containing [top-left, top-right, bottom-right,
bottom-left] of the original image with shape Bx8x3.
@@ -456,10 +429,8 @@ def apply_perspective3d(
- params['align_corners']: Boolean tensor.
Returns:
- torch.Tensor: Perspectively transformed tensor.
+ torch.Tensor: Perspectively transformed tensor with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
_, _, depth, height, width = input.shape
@@ -480,11 +451,12 @@ def apply_perspective3d(
return out_data.view_as(input)
+@_validate_input3d
def compute_perspective_transformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
- r"""Compute the applied transformation matrix :math: `(*, 4, 4)`.
+ r"""Compute the perspective transformation matrix :math: `(*, 4, 4)`.
Args:
- input (torch.Tensor): Tensor to be transformed with shape (D, H, W), (C, D, H, W), (B, C, D, H, W).
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]):
- params['start_points']: Tensor containing [top-left, top-right, bottom-right,
bottom-left] of the orignal image with shape Bx8x3.
@@ -492,12 +464,10 @@ def compute_perspective_transformation3d(input: torch.Tensor, params: Dict[str,
bottom-left] of the transformed image with shape Bx8x3.
Returns:
- torch.Tensor: The applied transformation matrix :math: `(*, 4, 4)`
+ torch.Tensor: The perspective transformation matrix :math: `(*, 4, 4)`
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
perspective_transform: torch.Tensor = get_perspective_transform3d(
- params['start_points'], params['end_points']).type_as(input)
+ params['start_points'], params['end_points']).to(input)
transform: torch.Tensor = K.eye_like(4, input)
@@ -506,18 +476,16 @@ def compute_perspective_transformation3d(input: torch.Tensor, params: Dict[str,
return transform
+@_validate_input3d
def apply_equalize3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
r"""Equalize a tensor volume or a batch of tensors volumes with given random parameters.
Args:
- input (torch.Tensor): Tensor to be transformed with shape :math:`(D, H, W)`,
- :math:`(C, D, H, W)`, :math:`(*, C, D, H, W)`.
+ input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.
params (Dict[str, torch.Tensor]): shall be empty.
Returns:
- torch.Tensor: The equalized input. :math:`(D, H, W)`, :math:`(C, D, H, W)`, :math:`(*, C, D, H, W)`.
+ torch.Tensor: Equalized input with shape :math:`(*, C, D, H, W)`.
"""
- input = _transform_input3d(input)
- _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64])
return equalize3d(input)
diff --git a/kornia/augmentation/utils/__init__.py b/kornia/augmentation/utils/__init__.py
index 65ff345a2..3c32bae97 100644
--- a/kornia/augmentation/utils/__init__.py
+++ b/kornia/augmentation/utils/__init__.py
@@ -19,7 +19,7 @@ from kornia.augmentation.utils.helpers import (
_adapted_beta,
_shape_validation,
_validate_input,
- _validate_input3D,
+ _validate_input3d,
_transform_output_shape
)
@@ -42,6 +42,6 @@ __all__ = [
"_singular_range_check",
"_tuple_range_reader",
"_validate_input",
- "_validate_input3D",
+ "_validate_input3d",
"_transform_output_shape"
]
diff --git a/kornia/augmentation/utils/helpers.py b/kornia/augmentation/utils/helpers.py
index 119f7e5e9..c81160770 100644
--- a/kornia/augmentation/utils/helpers.py
+++ b/kornia/augmentation/utils/helpers.py
@@ -29,7 +29,7 @@ def _validate_input(f: Callable) -> Callable:
return wrapper
-def _validate_input3D(f: Callable) -> Callable:
+def _validate_input3d(f: Callable) -> Callable:
r"""Validates the 3D input of the wrapped function.
Args:
diff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.py
index f82d48279..852b9bf8c 100644
--- a/kornia/enhance/adjust.py
+++ b/kornia/enhance/adjust.py
@@ -564,7 +564,7 @@ def sharpness(input: torch.Tensor, factor: Union[float, torch.Tensor]) -> torch.
If 1-d tensor, input will be sharpened element-wisely, len(factor) == len(input).
Returns:
- torch.Tensor: Sharpened image or images.
+ torch.Tensor: Sharpened image or images with shape :math:`(B, C, H, W)`.
Example:
>>> _ = torch.manual_seed(0)
@@ -698,7 +698,7 @@ def equalize(input: torch.Tensor) -> torch.Tensor:
input (torch.Tensor): image tensor to equalize with shapes like :math:`(C, H, W)` or :math:`(B, C, H, W)`.
Returns:
- torch.Tensor: Sharpened image or images with shape as the input.
+ torch.Tensor: Equalized image tensor with shape :math:`(B, C, H, W)`.
Example:
>>> _ = torch.manual_seed(0)
@@ -733,7 +733,7 @@ def equalize3d(input: torch.Tensor) -> torch.Tensor:
input (torch.Tensor): image tensor with shapes like :math:`(C, D, H, W)` or :math:`(B, C, D, H, W)` to equalize.
Returns:
- torch.Tensor: Sharpened image or images with same shape as the input.
+ torch.Tensor: Equalized volume with shape :math:`(B, C, D, H, W)`.
"""
input = _to_bcdhw(input)
diff --git a/kornia/utils/image.py b/kornia/utils/image.py
index d20a0c2ff..bca9f5061 100644
--- a/kornia/utils/image.py
+++ b/kornia/utils/image.py
@@ -45,14 +45,12 @@ def image_to_tensor(image: np.ndarray, keepdim: bool = True) -> torch.Tensor:
return tensor.unsqueeze(0) if not keepdim else tensor
-def _to_bchw(tensor: torch.Tensor, color_channel_num: Optional[int] = None) -> torch.Tensor:
+def _to_bchw(tensor: torch.Tensor) -> torch.Tensor:
"""Converts a PyTorch tensor image to BCHW format.
Args:
tensor (torch.Tensor): image of the form :math:`(H, W)`, :math:`(C, H, W)`, :math:`(H, W, C)` or
:math:`(B, C, H, W)`.
- color_channel_num (Optional[int]): Color channel of the input tensor.
- If None, it will not alter the input channel.
Returns:
torch.Tensor: input tensor of the form :math:`(B, C, H, W)`.
@@ -69,22 +67,15 @@ def _to_bchw(tensor: torch.Tensor, color_channel_num: Optional[int] = None) -> t
if len(tensor.shape) == 3:
tensor = tensor.unsqueeze(0)
- # TODO(jian): this function is never used. Besides is not feasible for torchscript.
- # In addition, the docs must be updated. I don't understand what is doing.
- # if color_channel_num is not None and color_channel_num != 1:
- # channel_list = [0, 1, 2, 3]
- # channel_list.insert(1, channel_list.pop(color_channel_num))
- # tensor = tensor.permute(*channel_list)
return tensor
-def _to_bcdhw(tensor: torch.Tensor, color_channel_num: Optional[int] = None) -> torch.Tensor:
- """Converts a PyTorch tensor image to BCHW format.
+def _to_bcdhw(tensor: torch.Tensor) -> torch.Tensor:
+ """Converts a PyTorch tensor image to BCDHW format.
+
Args:
tensor (torch.Tensor): image of the form :math:`(D, H, W)`, :math:`(C, D, H, W)`, :math:`(D, H, W, C)` or
:math:`(B, C, D, H, W)`.
- color_channel_num (Optional[int]): Color channel of the input tensor.
- If None, it will not alter the input channel.
Returns:
torch.Tensor: input tensor of the form :math:`(B, C, D, H, W)`.
@@ -101,12 +92,6 @@ def _to_bcdhw(tensor: torch.Tensor, color_channel_num: Optional[int] = None) ->
if len(tensor.shape) == 4:
tensor = tensor.unsqueeze(0)
- # TODO(jian): this function is never used. Besides is not feasible for torchscript.
- # In addition, the docs must be updated. I don't understand what is doing.
- # if color_channel_num is not None and color_channel_num != 1:
- # channel_list = [0, 1, 2, 3, 4]
- # channel_list.insert(1, channel_list.pop(color_channel_num))
- # tensor = tensor.permute(*channel_list)
return tensor