Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix images docs paths and improves auto typing (#1108)

Edgar Ribaba8dd5dc84fe
diff --git a/Makefile b/Makefile
index fd5efff05..6cc611f18 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ docstyle: FORCE
pydocstyle kornia/
build-docs: FORCE
- cd docs; make clean images html
+ cd docs; make clean html
install: FORCE
python setup.py install
diff --git a/docs/Makefile b/docs/Makefile
index ea1edd839..d85a34c26 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -22,7 +22,6 @@ help:
clean:
@echo "Removing everything under 'build'.."
@rm -rf $(BUILDDIR)/html/ $(BUILDDIR)/doctrees
- @rm -rf $(SOURCEDIR)/_static/*.jpg
images:
python3 generate_example_images.py
diff --git a/docs/generate_example_images.py b/docs/generate_example_images.py
index 7717a3f14..58348ed31 100644
--- a/docs/generate_example_images.py
+++ b/docs/generate_example_images.py
@@ -1,6 +1,8 @@
import importlib
+import math
import os
from pathlib import Path
+from typing import Optional, Tuple
import cv2
import numpy as np
@@ -9,62 +11,145 @@ import torch
import kornia as K
-mod = importlib.import_module("kornia.augmentation")
-BASE_IMAGE_URL: str = "https://raw.githubusercontent.com/kornia/data/main/panda.jpg"
-OUTPUT_PATH = Path(__file__).absolute().parent / "build/html/_static"
-os.makedirs(OUTPUT_PATH, exist_ok=True)
+def read_img_from_url(url: str, resize_to: Optional[Tuple[int, int]] = None) -> torch.Tensor:
+ # perform request
+ response = requests.get(url).content
+ # convert to array of ints
+ nparr = np.frombuffer(response, np.uint8)
+ # convert to image array
+ img: np.ndarray = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)
+ if resize_to is None:
+ img = cv2.resize(img, (186, int(img.shape[0] / img.shape[1] * 224)))
+ else:
+ img = cv2.resize(img, resize_to)
+ # convert the image to a tensor
+ img_t: torch.Tensor = K.utils.image_to_tensor(img, keepdim=False) # 1xCxHXW
+ img_t = img_t.float() / 255.0
+ return img_t
-# perform request
-response = requests.get(BASE_IMAGE_URL).content
-# convert to array of ints
-nparr = np.frombuffer(response, np.uint8)
+def main():
+ # load the images
+ BASE_IMAGE_URL: str = "https://raw.githubusercontent.com/kornia/data/main/panda.jpg"
+ BASE_IMAGE_URL2: str = "https://raw.githubusercontent.com/kornia/data/main/simba.png"
+ OUTPUT_PATH = Path(__file__).absolute().parent / "source/_static/img"
+ os.makedirs(OUTPUT_PATH, exist_ok=True)
+ print(f"Pointing images to path {OUTPUT_PATH}.")
+ img = read_img_from_url(BASE_IMAGE_URL)
+ img2 = read_img_from_url(BASE_IMAGE_URL2, img.shape[-2:][::-1])
-# convert to image array
-img: np.ndarray = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)
+ # TODO: make this more generic for modules out of kornia.augmentation
+ # Dictionary containing the transforms to generate the sample images:
+ # Key: Name of the transform class.
+ # Value: (parameters, num_samples, seed)
+ mod = importlib.import_module("kornia.augmentation")
+ augmentations_list: dict = {
+ "CenterCrop": ((96, 96), 1, 2018),
+ "ColorJitter": ((0.3, 0.3, 0.3, 0.3), 2, 2018),
+ "RandomAffine": (((-15.0, 20.0), (0.1, 0.1), (0.7, 1.3), 20), 2, 2019),
+ "RandomBoxBlur": (((7, 7),), 1, 2020),
+ "RandomCrop": ((img.shape[-2:], (50, 50)), 2, 2020),
+ "RandomChannelShuffle": ((), 1, 2020),
+ "RandomElasticTransform": (((63, 63), (32, 32), (2.0, 2.0)), 2, 2018),
+ "RandomEqualize": ((), 1, 2020),
+ "RandomErasing": (((0.2, 0.4), (0.3, 1 / 0.3)), 2, 2017),
+ "RandomFisheye": ((torch.tensor([-0.3, 0.3]), torch.tensor([-0.3, 0.3]), torch.tensor([0.9, 1.0])), 2, 2020),
+ "RandomGaussianBlur": (((3, 3), (0.1, 2.0)), 1, 2020),
+ "RandomGaussianNoise": ((0.0, 0.05), 1, 2020),
+ "RandomGrayscale": ((), 1, 2020),
+ "RandomHorizontalFlip": ((), 1, 2020),
+ "RandomInvert": ((), 1, 2020),
+ "RandomMotionBlur": ((7, 35.0, 0.5), 2, 2020),
+ "RandomPerspective": ((0.2,), 2, 2020),
+ "RandomPosterize": (((1, 4),), 2, 2016),
+ "RandomResizedCrop": ((img.shape[-2:], (1.0, 2.0), (1.0, 2.0)), 2, 2020),
+ "RandomRotation": ((45.0,), 2, 2019),
+ "RandomSharpness": ((16.0,), 1, 2019),
+ "RandomSolarize": ((0.2, 0.2), 2, 2019),
+ "RandomVerticalFlip": ((), 1, 2020),
+ "RandomThinPlateSpline": ((), 1, 2020),
+ }
-# convert the image to a tensor
-img_t: torch.Tensor = K.utils.image_to_tensor(img, keepdim=False) # 1xCxHXW
-img_t = img_t.float() / 255.0
+ # ITERATE OVER THE TRANSFORMS
+ for aug_name, (args, num_samples, seed) in augmentations_list.items():
+ img_in = img.repeat(num_samples, 1, 1, 1)
+ # dynamically create the class instance
+ cls = getattr(mod, aug_name)
+ aug = cls(*args, p=1.0)
+ # set seed
+ torch.manual_seed(seed)
+ # apply the augmentaiton to the image and concat
+ out = aug(img_in)
-# TODO: make this more generic for modules out of kornia.augmentation
-# Dictionary containing the transforms to generate the sample images:
-# Key: Name of the transform class.
-# Value: The default parameters to use.
-augmentations_list: dict = {
- "ColorJitter": (0.1, 0.1, 0.1, 0.1),
- "RandomAffine": ((-15.0, 20.0),),
- "RandomBoxBlur": ((7, 7),),
- "RandomChannelShuffle": (),
- "RandomErasing": ((0.4, 0.8), (0.3, 1 / 0.3)),
- "RandomElasticTransform": ((63, 63), (32, 32), (1.0, 1.0)),
- "RandomEqualize": (),
- "RandomFisheye": (torch.tensor([-0.3, 0.3]), torch.tensor([-0.3, 0.3]), torch.tensor([0.9, 1.0])),
- "RandomGrayscale": (),
- "RandomGaussianNoise": (0.0, 0.05),
- "RandomHorizontalFlip": (),
- "RandomInvert": (),
- "RandomMotionBlur": (7, 35.0, 0.5),
- "RandomPerspective": (0.2,),
- "RandomPosterize": (3,),
- "RandomResizedCrop": ((510, 1020), (3.0, 3.0), (2.0, 2.0)),
- "RandomRotation": (45.0,),
- "RandomSharpness": (1.0,),
- "RandomSolarize": (0.1,),
- "RandomVerticalFlip": (),
- "RandomThinPlateSpline": (),
-}
+ if aug_name == "CenterCrop":
+ out = K.geometry.resize(out, img_in.shape[-2:])
-# ITERATE OVER THE TRANSFORMS
+ out = torch.cat([img_in[0], *[out[i] for i in range(out.size(0))]], dim=-1)
+ # save the output image
+ out_np = K.utils.tensor_to_image((out * 255.0).byte())
+ cv2.imwrite(str(OUTPUT_PATH / f"{aug_name}.png"), out_np)
+ sig = f"{aug_name}({', '.join([str(a) for a in args])}, p=1.0)"
+ print(f"Generated image example for {aug_name}. {sig}")
-for aug_name, args in augmentations_list.items():
- # dynamically create the class instance
- cls = getattr(mod, aug_name)
- aug = cls(*args, p=1.0)
- # apply the augmentaiton to the image and concat
- out = aug(img_t)
- out = torch.cat([img_t, out], dim=-1)
- # save the output image
- out_np = K.utils.tensor_to_image((out * 255.0).byte())
- cv2.imwrite(str(OUTPUT_PATH / f"{aug_name}.jpg"), out_np)
+ mod = importlib.import_module("kornia.augmentation")
+ mix_augmentations_list: dict = {
+ "RandomMixUp": (((0.3, 0.4),), 2, 20),
+ "RandomCutMix": ((img.shape[-2], img.shape[-1]), 2, 2019),
+ }
+ # ITERATE OVER THE TRANSFORMS
+ for aug_name, (args, num_samples, seed) in mix_augmentations_list.items():
+ img_in = torch.cat([img, img2])
+ # dynamically create the class instance
+ cls = getattr(mod, aug_name)
+ aug = cls(*args, p=1.0)
+ # set seed
+ torch.manual_seed(seed)
+ # apply the augmentaiton to the image and concat
+ out, _ = aug(img_in, torch.tensor([0, 1]))
+ out = torch.cat([img_in[0], img_in[1], *[out[i] for i in range(out.size(0))]], dim=-1)
+ # save the output image
+ out_np = K.utils.tensor_to_image((out * 255.0).byte())
+ cv2.imwrite(str(OUTPUT_PATH / f"{aug_name}.png"), out_np)
+ sig = f"{aug_name}({', '.join([str(a) for a in args])}, p=1.0)"
+ print(f"Generated image example for {aug_name}. {sig}")
+
+ mod = importlib.import_module("kornia.color")
+ color_transforms_list: dict = {
+ "rgb_to_bgr": ((), 1),
+ "rgb_to_grayscale": ((), 1),
+ "rgb_to_hsv": ((), 1),
+ "rgb_to_hls": ((), 1),
+ "rgb_to_luv": ((), 1),
+ "rgb_to_lab": ((), 1),
+ # "rgb_to_rgba": ((1.,), 1),
+ "rgb_to_xyz": ((), 1),
+ "rgb_to_ycbcr": ((), 1),
+ "rgb_to_yuv": ((), 1),
+ "rgb_to_linear_rgb": ((), 1),
+ }
+ # ITERATE OVER THE TRANSFORMS
+ for fn_name, (args, num_samples) in color_transforms_list.items():
+ # import function and apply
+ fn = getattr(mod, fn_name)
+ out = fn(img2, *args)
+ # perform normalization to visualize
+ if fn_name == "rgb_to_lab":
+ out = out[:, :1] / 100.0
+ elif fn_name == "rgb_to_hsv":
+ out[:, :1] = out[:, :1] / 2 * math.pi
+ elif fn_name == "rgb_to_luv":
+ out = out[:, :1] / 116.0
+ # repeat channels for grayscale
+ if out.shape[1] != 3:
+ out = out.repeat(1, 3, 1, 1)
+ # save the output image
+ out = torch.cat([img2[0], *[out[i] for i in range(out.size(0))]], dim=-1)
+ out_np = K.utils.tensor_to_image((out * 255.0).byte())
+ cv2.imwrite(str(OUTPUT_PATH / f"{fn_name}.png"), out_np)
+ sig = f"{fn_name}({', '.join([str(a) for a in args])})"
+ print(f"Generated image example for {fn_name}. {sig}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 2a4b941d6..2758f7445 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -4,9 +4,10 @@ torchvision
opencv-python
matplotlib
# sphinx
-sphinx >=2.1, <3
-sphinx_rtd_theme
-sphinxcontrib-bibtex<2.0.0
-nbsphinx
-nbconvert
-notebook
+sphinx>=4.0
+sphinx_rtd_theme>0.5
+sphinxcontrib-bibtex
+sphinx-autodoc-typehints>=1.0
+sphinx-copybutton>=0.3
+sphinx-autodoc-defaultargs
+PyYAML>=5.1,<=5.4.1
diff --git a/docs/source/augmentation.base.rst b/docs/source/augmentation.base.rst
index c332f5f95..8cdabcb12 100644
--- a/docs/source/augmentation.base.rst
+++ b/docs/source/augmentation.base.rst
@@ -3,24 +3,10 @@ Base Classes
.. currentmodule:: kornia.augmentation.base
+This is the base class for creating a new transform using `kornia.augmentation`.
+The user only needs to override: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`.
-This is the base class for creating a new transform. The user only needs to override: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`.
-
-
-.. autoclass:: AugmentationBase2D
-
- .. automethod:: generate_parameters
- .. automethod:: compute_transformation
- .. automethod:: apply_transform
-
-.. autoclass:: AugmentationBase3D
-
- .. automethod:: generate_parameters
- .. automethod:: compute_transformation
- .. automethod:: apply_transform
-
-
-Create your own transformation:
+Create your own transformations with the following snippet:
.. code-block:: python
@@ -59,3 +45,15 @@ Create your own transformation:
# apply transformation and return
output = K.warp_affine(input, transform, (H, W))
return (output, transform)
+
+.. autoclass:: AugmentationBase2D
+
+ .. automethod:: generate_parameters
+ .. automethod:: compute_transformation
+ .. automethod:: apply_transform
+
+.. autoclass:: AugmentationBase3D
+
+ .. automethod:: generate_parameters
+ .. automethod:: compute_transformation
+ .. automethod:: apply_transform
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 20659abea..60052016b 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -1,8 +1,20 @@
+import importlib.util
import os
import sys
import sphinx_rtd_theme
+# readthedocs generated the whole documentation in an isolated environment
+# by cloning the git repo. Thus, any on-the-fly operation will not effect
+# on the resulting documentation. We therefore need to import and run the
+# corresponding code here.
+spec = importlib.util.spec_from_file_location("generate_example_images", "../generate_example_images.py")
+generate_example_images = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(generate_example_images)
+
+# Pre-generate the example images
+generate_example_images.main()
+
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -24,18 +36,25 @@ extensions = [
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
- 'sphinx.ext.todo',
- 'sphinx.ext.coverage',
+ # 'sphinx.ext.todo',
+ # 'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
+ 'sphinx_autodoc_typehints',
+ 'sphinx_autodoc_defaultargs',
+ 'sphinx_copybutton',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
- 'nbsphinx',
'sphinxcontrib.bibtex',
]
+# subsitutes the default values
+docstring_default_arg_substitution = 'Default: '
+
+bibtex_bibfiles = ['references.bib']
napoleon_use_ivar = True
+# TODO: review this number
googleanalytics_id = 'UA-90545585-1'
googleanalytics_enabled = True
@@ -178,11 +197,3 @@ intersphinx_mapping = {
'numpy': ('http://numpy.org/doc/stable/', None),
'torch': ('http://pytorch.org/docs/stable/', None),
}
-
-examples_dir = os.path.join(current_path, "tutorials")
-sphinx_gallery_conf = {
- 'doc_module': 'kornia',
- 'examples_dirs': [examples_dir], # path to your example scripts
- 'gallery_dirs': ['tutorials'], # path where to save gallery generated output
- 'filename_pattern': './',
-}
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 5f23fc4eb..a1acd9417 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -41,4 +41,7 @@ Indices and tables
* :ref:`modindex`
* :ref:`search`
-.. bibliography:: references.bib
+References
+==========
+
+.. bibliography::
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index c3917dabf..8d2bb52ac 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -48,7 +48,7 @@ from .utils import _range_bound, _transform_input
class RandomHorizontalFlip(GeometricAugmentationBase2D):
r"""Applies a random horizontal flip to a tensor image or a batch of tensor images with a given probability.
- .. image:: _static/RandomHorizontalFlip.jpg
+ .. image:: _static/img/RandomHorizontalFlip.png
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,
@@ -57,13 +57,13 @@ class RandomHorizontalFlip(GeometricAugmentationBase2D):
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
- input tensor. If ``False`` and the input is a tuple the applied transformation
- wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability of the image being flipped.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -109,16 +109,16 @@ class RandomHorizontalFlip(GeometricAugmentationBase2D):
class RandomVerticalFlip(GeometricAugmentationBase2D):
r"""Applies a random vertical flip to a tensor image or a batch of tensor images with a given probability.
- .. image:: _static/RandomVerticalFlip.jpg
+ .. image:: _static/img/RandomVerticalFlip.png
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
- input tensor. If ``False`` and the input is a tuple the applied transformation
- wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability of the image being flipped.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -164,20 +164,20 @@ class RandomVerticalFlip(GeometricAugmentationBase2D):
class ColorJitter(IntensityAugmentationBase2D):
r"""Applies a random transformation to the brightness, contrast, saturation and hue of a tensor image.
- .. image:: _static/ColorJitter.jpg
+ .. image:: _static/img/ColorJitter.png
Args:
- p (float): probability of applying the transformation. Default value is 1.
- brightness (float or tuple): Default value is 0.
- contrast (float or tuple): Default value is 0.
- saturation (float or tuple): Default value is 0.
- hue (float or tuple): Default value is 0.
- 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.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability of applying the transformation.
+ brightness: The brightness factor to apply.
+ contrast: The contrast factor to apply.
+ saturation: The saturation factor to apply.
+ hue: The hue factor to apply.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -266,16 +266,16 @@ class ColorJitter(IntensityAugmentationBase2D):
class RandomGrayscale(IntensityAugmentationBase2D):
r"""Applies random transformation to Grayscale according to a probability p value.
- .. image:: _static/RandomGrayscale.jpg
+ .. image:: _static/img/RandomGrayscale.png
Args:
- p (float): probability of the image to be transformed to grayscale. Default value is 0.1.
- 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.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability of the image to be transformed to grayscale.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -326,7 +326,7 @@ class RandomGrayscale(IntensityAugmentationBase2D):
class RandomErasing(IntensityAugmentationBase2D):
r"""Erases a random rectangle of a tensor image according to a probability p value.
- .. image:: _static/RandomErasing.jpg
+ .. image:: _static/img/RandomErasing.png
The operator removes image parts and fills them with zero values at a selected rectangle
for each of the images in the batch.
@@ -336,12 +336,12 @@ class RandomErasing(IntensityAugmentationBase2D):
between [ratio[0], ratio[1])
Args:
- p (float): probability that the random erasing operation will be performed. Default value is 0.5.
- scale (Tuple[float, float]): range of proportion of erased area against input image.
- ratio (Tuple[float, float]): range of aspect ratio of erased area.
- same_on_batch (bool): apply the same transformation across the batch. Default: False
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability that the random erasing operation will be performed.
+ scale: range of proportion of erased area against input image.
+ ratio: range of aspect ratio of erased area.
+ same_on_batch: apply the same transformation across the batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -416,18 +416,18 @@ class RandomErasing(IntensityAugmentationBase2D):
class RandomPerspective(GeometricAugmentationBase2D):
r"""Applies a random perspective transformation to an image tensor with a given probability.
- .. image:: _static/RandomPerspective.jpg
+ .. image:: _static/img/RandomPerspective.png
Args:
- p (float): probability of the image being perspectively transformed. Default value is 0.5.
- distortion_scale(float): it controls the degree of distortion and ranges from 0 to 1. Default value is 0.5.
- resample (int, str or kornia.Resample): Default: Resample.BILINEAR.
- return_transform (bool): if ``True`` return the matrix describing the transformation
- applied to each. Default: False.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- align_corners(bool): interpolation flag. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: probability of the image being perspectively transformed..
+ distortion_scale: it controls the degree of distortion and ranges from 0 to 1.
+ resample: the interpolation method to use.
+ return_transform: if ``True`` return the matrix describing the transformation
+ applied to each.
+ same_on_batch: apply the same transformation across the batch. Default: False.
+ align_corners: interpolation flag.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -511,38 +511,34 @@ class RandomPerspective(GeometricAugmentationBase2D):
class RandomAffine(GeometricAugmentationBase2D):
r"""Applies a random 2D affine transformation to a tensor image.
- .. image:: _static/RandomAffine.jpg
+ .. image:: _static/img/RandomAffine.png
The transformation is computed so that the image center is kept invariant.
Args:
- p (float): probability of applying the transformation. Default value is 0.5.
- degrees (float or tuple): Range of degrees to select from.
+ p: probability of applying the transformation.
+ degrees: Range of degrees to select from.
If degrees is a number instead of sequence like (min, max), the range of degrees
will be (-degrees, +degrees). Set to 0 to deactivate rotations.
- translate (tuple, optional): tuple of maximum absolute fraction for horizontal
+ translate: tuple of maximum absolute fraction for horizontal
and vertical translations. For example translate=(a, b), then horizontal shift
is randomly sampled in the range -img_width * a < dx < img_width * a and vertical shift is
randomly sampled in the range -img_height * b < dy < img_height * b. Will not translate by default.
- scale (tuple, optional): scaling factor interval.
+ scale: scaling factor interval.
If (a, b) represents isotropic scaling, the scale is randomly sampled from the range a <= scale <= b.
If (a, b, c, d), the scale is randomly sampled from the range a <= scale_x <= b, c <= scale_y <= d.
Will keep original scale by default.
- shear (sequence or float, optional): Range of degrees to select from.
+ shear: Range of degrees to select from.
If float, a shear parallel to the x axis in the range (-shear, +shear) will be apllied.
If (a, b), a shear parallel to the x axis in the range (-shear, +shear) will be apllied.
If (a, b, c, d), then x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3])
will be applied. Will not apply shear by default.
- resample (int, str or kornia.Resample): resample mode from "nearest" (0) or "bilinear" (1).
- Default: Resample.BILINEAR.
- padding_mode (int, str or kornia.SamplePadding): padding mode from "zeros" (0), "border" (1)
- or "refection" (2). Default: SamplePadding.ZEROS.
- return_transform (bool): if ``True`` return the matrix describing the transformation
- applied to each. Default: False.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- align_corners(bool): interpolation flag. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ resample: resample mode from "nearest" (0) or "bilinear" (1).
+ padding_mode: padding mode from "zeros" (0), "border" (1) or "refection" (2).
+ return_transform: if ``True`` return the matrix describing the transformation applied to each.
+ same_on_batch: apply the same transformation across the batch.
+ align_corners: interpolation flag.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -709,19 +705,23 @@ class RandomAffine(GeometricAugmentationBase2D):
class CenterCrop(GeometricAugmentationBase2D):
r"""Crops a given image tensor at the center.
+ .. image:: _static/img/CenterCrop.png
+
Args:
- p (float): probability of applying the transformation for the whole batch. Default value is 1.
- size (Tuple[int, int] or int): Desired output size (out_h, out_w) of the crop.
+ size: 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.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
- cropping_mode (str): The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
- on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
- to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
- differentiability. Default: `slice`.
+ align_corners: interpolation flag.
+ resample: The interpolation mode.
+ return_transform: if ``True`` return the matrix describing the transformation
+ applied to each.
+ p: probability of applying the transformation for the whole batch.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
+ cropping_mode: The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
+ on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
+ to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
+ differentiability.
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -837,20 +837,20 @@ class CenterCrop(GeometricAugmentationBase2D):
class RandomRotation(GeometricAugmentationBase2D):
r"""Applies a random rotation to a tensor image or a batch of tensor images given an amount of degrees.
- .. image:: _static/RandomRotation.jpg
+ .. image:: _static/img/RandomRotation.png
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
+ p: probability of applying the transformation.
+ degrees: range of degrees to select from. If degrees is a number the
range of degrees to select from will be (-degrees, +degrees).
- 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.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- align_corners(bool): interpolation flag. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ resample: Default: the interpolation mode.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ align_corners: interpolation flag.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -938,34 +938,36 @@ class RandomRotation(GeometricAugmentationBase2D):
class RandomCrop(GeometricAugmentationBase2D):
r"""Crops random patches of a tensor image on a given size.
+ .. image:: _static/img/RandomCrop.png
+
Args:
- p (float): probability of applying the transformation for the whole batch. Default value is 1.0.
- size (Tuple[int, int]): Desired output size (out_h, out_w) of the crop.
+ p: probability of applying the transformation for the whole batch.
+ size: 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
+ padding: 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
respectively. If a sequence of length 2 is provided, it is used to
pad left/right, top/bottom borders, respectively.
- pad_if_needed (boolean): It will pad the image if smaller than the
+ pad_if_needed: It will pad the image if smaller than the
desired size to avoid raising an exception. Since cropping is done
after padding, the padding seems to be done at a random offset.
fill: Pixel fill value for constant fill. Default is 0. If a tuple of
length 3, it is used to fill R, G, B channels respectively.
- This value is only used when the padding_mode is constant
- padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
- 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
- same_on_batch (bool): apply the same transformation across the batch. Default: False
- align_corners(bool): interpolation flag. Default: True.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
- cropping_mode (str): The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
- on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
- to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
- differentiability. Default: `slice`.
+ This value is only used when the padding_mode is constant.
+ padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric.
+ resample: the interpolation mode.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ align_corners: interpolation flag.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
+ cropping_mode: The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
+ on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
+ to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
+ differentiability.
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1168,25 +1170,25 @@ class RandomCrop(GeometricAugmentationBase2D):
class RandomResizedCrop(GeometricAugmentationBase2D):
r"""Crops random patches in an image tensor and resizes to a given size.
- .. image:: _static/RandomResizedCrop.jpg
+ .. image:: _static/img/RandomResizedCrop.png
Args:
- size (Tuple[int, int]): Desired output size (out_h, out_w) of each edge.
+ size: 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.
- 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.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- align_corners(bool): interpolation flag. Default: False.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
- cropping_mode (str): The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
- on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
- to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
- differentiability. Default: `slice`.
+ resample: the interpolation mode.
+ 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
+ wont be concatenated.
+ same_on_batch: apply the same transformation across the batch.
+ align_corners: interpolation flag.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
+ cropping_mode: The used algorithm to crop. ``slice`` will use advanced slicing to extract the tensor based
+ on the sampled indices. ``resample`` will use `warp_affine` using the affine transformation
+ to extract and resize at once. Use `slice` for efficiency, or `resample` for proper
+ differentiability.
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1331,11 +1333,11 @@ class Normalize(IntensityAugmentationBase2D):
Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
- mean (torch.Tensor): Mean for each channel.
- std (torch.Tensor): Standard deviations for each channel.
+ mean: Mean for each channel.
+ std: Standard deviations for each channel.
Return:
- torch.Tensor: Normalised tensor with same size as input :math:`(*, C, H, W)`.
+ Normalised tensor with same size as input :math:`(*, C, H, W)`.
Examples:
@@ -1377,11 +1379,11 @@ class Denormalize(IntensityAugmentationBase2D):
Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
- mean (torch.Tensor): Mean for each channel.
- std (torch.Tensor): Standard deviations for each channel.
+ mean: Mean for each channel.
+ std: Standard deviations for each channel.
Return:
- torch.Tensor: Denormalised tensor with same size as input :math:`(*, C, H, W)`.
+ Denormalised tensor with same size as input :math:`(*, C, H, W)`.
Examples:
@@ -1417,26 +1419,26 @@ class Denormalize(IntensityAugmentationBase2D):
class RandomMotionBlur(IntensityAugmentationBase2D):
r"""Perform motion blur on 2D images (4D tensor).
- .. image:: _static/RandomMotionBlur.jpg
+ .. image:: _static/img/RandomMotionBlur.png
Args:
- p (float): probability of applying the transformation. Default value is 0.5.
- kernel_size (int or Tuple[int, int]): motion kernel size (odd and positive).
+ p: probability of applying the transformation.
+ kernel_size: motion kernel size (odd and positive).
If int, the kernel will have a fixed size.
If Tuple[int, int], it will randomly generate the value from the range batch-wisely.
- angle (float or Tuple[float, float]): angle of the motion blur in degrees (anti-clockwise rotation).
+ angle: angle of the motion blur in degrees (anti-clockwise rotation).
If float, it will generate the value from (-angle, angle).
- direction (float or Tuple[float, float]): forward/backward direction of the motion blur.
+ direction: forward/backward direction of the motion blur.
Lower values towards -1.0 will point the motion blur towards the back (with angle provided via angle),
while higher values towards 1.0 will point the motion blur forward. A value of 0.0 leads to a
uniformly (but still angled) motion blur.
If float, it will generate the value from (-direction, direction).
If Tuple[int, int], it will randomly generate the value from the range.
- border_type (int, str or kornia.BorderType): the padding mode to be applied before convolving.
- CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.
- resample (int, str or kornia.Resample): Default: Resample.NEAREST.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ border_type: the padding mode to be applied before convolving.
+ CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3.
+ resample: the interpolation mode.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1525,21 +1527,21 @@ class RandomMotionBlur(IntensityAugmentationBase2D):
class RandomSolarize(IntensityAugmentationBase2D):
r"""Solarize given tensor image or a batch of tensor images randomly.
- .. image:: _static/RandomSolarize.jpg
+ .. image:: _static/img/RandomSolarize.png
Args:
- p (float): probability of applying the transformation. Default value is 0.5.
- thresholds (float or tuple): Default value is 0.1.
+ p: probability of applying the transformation.
+ thresholds:
If float x, threshold will be generated from (0.5 - x, 0.5 + x).
If tuple (x, y), threshold will be generated from (x, y).
- additions (float or tuple): Default value is 0.1.
+ additions:
If float x, addition will be generated from (-x, x).
If tuple (x, y), addition will be generated from (x, y).
- 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
+ same_on_batch: apply the same transformation across the batch.
+ 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 wont be concatenated.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1606,19 +1608,18 @@ class RandomSolarize(IntensityAugmentationBase2D):
class RandomPosterize(IntensityAugmentationBase2D):
r"""Posterize given tensor image or a batch of tensor images randomly.
- .. image:: _static/RandomPosterize.jpg
+ .. image:: _static/img/RandomPosterize.png
Args:
- p (float): probability of applying the transformation. Default value is 0.5.
- bits (int or tuple): Integer that ranged from (0, 8], in which 0 gives black image and 8 gives the original.
+ p: probability of applying the transformation.
+ bits: Integer that ranged from (0, 8], in which 0 gives black image and 8 gives the original.
If int x, bits will be generated from (x, 8).
If tuple (x, y), bits will be generated from (x, y).
- Default value is 3.
- 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
+ same_on_batch: apply the same transformation across the batch.
+ 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 wont be concatenated.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1677,16 +1678,16 @@ class RandomPosterize(IntensityAugmentationBase2D):
class RandomSharpness(IntensityAugmentationBase2D):
r"""Sharpen given tensor image or a batch of tensor images randomly.
- .. image:: _static/RandomSharpness.jpg
+ .. image:: _static/img/RandomSharpness.png
Args:
- p (float): probability of applying the transformation. Default value is 0.5.
- sharpness (float or tuple): factor of sharpness strength. Must be above 0. Default value is 0.5.
- 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
+ p: probability of applying the transformation.
+ sharpness: factor of sharpness strength. Must be above 0.
+ same_on_batch: apply the same transformation across the batch.
+ 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 wont be concatenated.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1746,16 +1747,16 @@ class RandomSharpness(IntensityAugmentationBase2D):
class RandomEqualize(IntensityAugmentationBase2D):
r"""Equalize given tensor image or a batch of tensor images randomly.
- .. image:: _static/RandomEqualize.jpg
+ .. image:: _static/img/RandomEqualize.png
Args:
- p (float): Probability to equalize an image. Default value is 0.5.
- 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.
- keepdim (bool): whether to keep the output shape the same as input (True) or broadcast it
- to the batch form (False). Default: False.
+ p: Probability to equalize an image.
+ same_on_batch: apply the same transformation across the batch.
+ 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
+ wont be concatenated.
+ keepdim: whether to keep the output shape the same as input (True) or broadcast it
+ to the batch form (False).
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1797,16 +1798,17 @@ class RandomEqualize(IntensityAugmentationBase2D):
class RandomGaussianBlur(IntensityAugmentationBase2D):
r"""Apply gaussian blur given tensor image or a batch of tensor images randomly.
+ .. image:: _static/img/RandomGaussianBlur.png
+
Args:
- kernel_size (Tuple[int, int]): the size of the kernel.
- sigma (Tuple[float, float]): the standard deviation of the kernel.
- border_type (str): the padding mode to be applied before convolving.
- The expected modes are: ``'constant'``, ``'reflect'``,
- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ kernel_size: the size of the kernel.
+ sigma: the standard deviation of the kernel.
+ border_type: the padding mode to be applied before convolving.
+ The expected modes are: ``constant``, ``reflect``, ``replicate`` or ``circular``.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Shape:
- Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`, Optional: :math:`(B, 3, 3)`
@@ -1865,15 +1867,15 @@ class GaussianBlur(RandomGaussianBlur):
class RandomInvert(IntensityAugmentationBase2D):
r"""Invert the tensor images values randomly.
- .. image:: _static/RandomInvert.jpg
+ .. image:: _static/img/RandomInvert.png
Args:
- max_val (torch.Tensor): The expected maximum value in the input tensor. The shape has to
- according to the input tensor shape, or at least has to work with broadcasting. Default: 1.0.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ max_val: The expected maximum value in the input tensor. The shape has to
+ according to the input tensor shape, or at least has to work with broadcasting.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> rng = torch.manual_seed(0)
@@ -1910,13 +1912,13 @@ class RandomInvert(IntensityAugmentationBase2D):
class RandomChannelShuffle(IntensityAugmentationBase2D):
r"""Shuffles the channels of a batch of multi-dimensional images.
- .. image:: _static/RandomChannelShuffle.jpg
+ .. image:: _static/img/RandomChannelShuffle.png
Args:
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> rng = torch.manual_seed(0)
@@ -1954,15 +1956,15 @@ class RandomChannelShuffle(IntensityAugmentationBase2D):
class RandomGaussianNoise(IntensityAugmentationBase2D):
r"""Add gaussian noise to a batch of multi-dimensional images.
- .. image:: _static/RandomGaussianNoise.jpg
+ .. image:: _static/img/RandomGaussianNoise.png
Args:
- mean (float): The mean of the gaussian distribution. Default: 0.
- std (float): The standard deviation of the gaussian distribution. Default: 1.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ mean: The mean of the gaussian distribution.
+ std: The standard deviation of the gaussian distribution.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> rng = torch.manual_seed(0)
@@ -2002,16 +2004,16 @@ class RandomGaussianNoise(IntensityAugmentationBase2D):
class RandomFisheye(GeometricAugmentationBase2D):
r"""Add random camera radial distortion.
- .. image:: _static/RandomFisheye.jpg
+ .. image:: _static/img/RandomFisheye.png
Args:
- center_x (torch.Tensor): Ranges to sample respect to x-coordinate center with shape (2,).
- center_y (torch.Tensor): Ranges to sample respect to y-coordinate center with shape (2,).
- gamma (torch.Tensor): Ranges to sample for the gamma values respect to optical center with shape (2,).
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ center_x: Ranges to sample respect to x-coordinate center with shape (2,).
+ center_y: Ranges to sample respect to y-coordinate center with shape (2,).
+ gamma: Ranges to sample for the gamma values respect to optical center with shape (2,).
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> img = torch.ones(1, 1, 2, 2)
@@ -2084,20 +2086,20 @@ class RandomFisheye(GeometricAugmentationBase2D):
class RandomElasticTransform(GeometricAugmentationBase2D):
r"""Add random elastic transformation to a tensor image.
- .. image:: _static/RandomElasticTransform.jpg
+ .. image:: _static/img/RandomElasticTransform.png
Args:
- kernel_size (Tuple[int, int]): the size of the Gaussian kernel. Default: (63, 63).
- sigma (Tuple[float, float]): The standard deviation of the Gaussian in the y and x directions,
- respecitvely. Larger sigma results in smaller pixel displacements. Default: (32, 32).
- alpha (Tuple[float, float]): The scaling factor that controls the intensity of the deformation
- in the y and x directions, respectively. Default: 1.
- align_corners (bool): Interpolation flag used by `grid_sample`. Default: False.
- mode (str): Interpolation mode used by `grid_sample`. Either 'bilinear' or 'nearest'. Default: 'bilinear'.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ kernel_size: the size of the Gaussian kernel.
+ sigma: The standard deviation of the Gaussian in the y and x directions,
+ respecitvely. Larger sigma results in smaller pixel displacements.
+ alpha: The scaling factor that controls the intensity of the deformation
+ 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'.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> img = torch.ones(1, 1, 2, 2)
@@ -2147,16 +2149,16 @@ class RandomElasticTransform(GeometricAugmentationBase2D):
class RandomThinPlateSpline(GeometricAugmentationBase2D):
r"""Add random noise to the Thin Plate Spline algorithm.
- .. image:: _static/RandomThinPlateSpline.jpg
+ .. image:: _static/img/RandomThinPlateSpline.png
Args:
- scale (float): the scale factor to apply to the destionation points. Default: 0.2.
- align_corners (bool): Interpolation flag used by `grid_sample`. Default: False.
- mode (str): Interpolation mode used by `grid_sample`. Either 'bilinear' or 'nearest'. Default: 'bilinear'.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ scale: the scale factor to apply to the destionation points.
+ align_corners: Interpolation flag used by ``grid_sample``.
+ mode: Interpolation mode used by `grid_sample`. Either 'bilinear' or 'nearest'.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch: apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> img = torch.ones(1, 1, 2, 2)
@@ -2203,18 +2205,17 @@ class RandomThinPlateSpline(GeometricAugmentationBase2D):
class RandomBoxBlur(GeometricAugmentationBase2D):
"""Adds random blur with a box filter to an image tensor.
- .. image:: _static/RandomBoxBlur.jpg
+ .. image:: _static/img/RandomBoxBlur.png
Args:
- kernel_size (Tuple[int, int]): the blurring kernel size.
- border_type (str): the padding mode to be applied before convolving.
- The expected modes are: ``'constant'``, ``'reflect'``,
- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.
- normalized (bool): if True, L1 norm of the kernel is set to 1.
- return_transform (bool): if ``True`` return the matrix describing the transformation applied to each
+ kernel_size: the blurring kernel size.
+ border_type: the padding mode to be applied before convolving.
+ The expected modes are: ``constant``, ``reflect``, ``replicate`` or ``circular``.
+ normalized: if True, L1 norm of the kernel is set to 1.
+ 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 wont be concatenated.
- same_on_batch (bool): apply the same transformation across the batch. Default: False.
- p (float): probability of applying the transformation. Default value is 0.5.
+ same_on_batch (bool): apply the same transformation across the batch.
+ p: probability of applying the transformation.
Examples:
>>> img = torch.ones(1, 1, 24, 24)
diff --git a/kornia/augmentation/mix_augmentation.py b/kornia/augmentation/mix_augmentation.py
index d5470fab7..7227867d2 100644
--- a/kornia/augmentation/mix_augmentation.py
+++ b/kornia/augmentation/mix_augmentation.py
@@ -12,6 +12,8 @@ from .utils import _shape_validation
class RandomMixUp(MixAugmentationBase):
r"""Apply MixUp augmentation to a batch of tensor images.
+ .. image:: _static/img/RandomMixUp.png
+
Implemention for `mixup: BEYOND EMPIRICAL RISK MINIMIZATION` :cite:`zhang2018mixup`.
The function returns (inputs, labels), in which the inputs is the tensor that contains the mixup images
@@ -123,6 +125,8 @@ class RandomMixUp(MixAugmentationBase):
class RandomCutMix(MixAugmentationBase):
r"""Apply CutMix augmentation to a batch of tensor images.
+ .. image:: _static/img/RandomCutMix.png
+
Implemention for `CutMix: Regularization Strategy to Train Strong Classifiers with
Localizable Features` :cite:`yun2019cutmix`.
diff --git a/kornia/color/gray.py b/kornia/color/gray.py
index c6a5514d6..96bb930b4 100644
--- a/kornia/color/gray.py
+++ b/kornia/color/gray.py
@@ -11,14 +11,16 @@ def rgb_to_grayscale(
) -> torch.Tensor:
r"""Convert a RGB image to grayscale version of image.
+ .. image:: _static/img/rgb_to_grayscale.png
+
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): RGB image to be converted to grayscale with shape :math:`(*,3,H,W)`.
- rgb_weights (torch.Tensor): Weights that will be applied on each channel (RGB).
+ image: RGB image to be converted to grayscale with shape :math:`(*,3,H,W)`.
+ rgb_weights: Weights that will be applied on each channel (RGB).
The sum of the weights should add up to one.
Returns:
- torch.Tensor: grayscale version of the image with shape :math:`(*,1,H,W)`.
+ grayscale version of the image with shape :math:`(*,1,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -57,10 +59,10 @@ def bgr_to_grayscale(image: torch.Tensor) -> torch.Tensor:
The image data is assumed to be in the range of (0, 1). First flips to RGB, then converts.
Args:
- image (torch.Tensor): BGR image to be converted to grayscale with shape :math:`(*,3,H,W)`.
+ image: BGR image to be converted to grayscale with shape :math:`(*,3,H,W)`.
Returns:
- torch.Tensor: grayscale version of the image with shape :math:`(*,1,H,W)`.
+ grayscale version of the image with shape :math:`(*,1,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index 031ceb2f1..f99db454b 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -7,13 +7,15 @@ import torch.nn as nn
def rgb_to_hls(image: torch.Tensor) -> torch.Tensor:
r"""Convert a RGB image to HLS.
+ .. image:: _static/img/rgb_to_hls.png
+
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): RGB image to be converted to HLS with shape :math:`(*, 3, H, W)`.
+ image: RGB image to be converted to HLS with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: HLS version of the image with shape :math:`(*, 3, H, W)`.
+ HLS version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -67,10 +69,10 @@ def hls_to_rgb(image: torch.Tensor) -> torch.Tensor:
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): HLS image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ image: HLS image to be converted to RGB with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*, 3, H, W)`.
+ RGB version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -114,7 +116,7 @@ class RgbToHls(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: HLS version of the image.
+ HLS version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -136,7 +138,7 @@ class HlsToRgb(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- input: :math:`(*, 3, H, W)`
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.py
index cd34e9f76..48ade7ef6 100644
--- a/kornia/color/hsv.py
+++ b/kornia/color/hsv.py
@@ -7,14 +7,16 @@ import torch.nn as nn
def rgb_to_hsv(image: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
r"""Convert an image from RGB to HSV.
+ .. image:: _static/img/rgb_to_hsv.png
+
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): RGB Image to be converted to HSV with shape of :math:`(*, 3, H, W)`.
- eps (float, optional): scalar to enforce numarical stability. Default: 1e-6.
+ image: RGB Image to be converted to HSV with shape of :math:`(*, 3, H, W)`.
+ eps: scalar to enforce numarical stability.
Returns:
- torch.Tensor: HSV version of the image with shape of :math:`(*, 3, H, W)`.
+ HSV version of the image with shape of :math:`(*, 3, H, W)`.
The H channel values are in the range 0..2pi. S and V are in the range 0..1.
Example:
@@ -66,10 +68,10 @@ def hsv_to_rgb(image: torch.Tensor) -> torch.Tensor:
The H channel values are assumed to be in the range 0..2pi. S and V are in the range 0..1.
Args:
- image (torch.Tensor): HSV Image to be converted to HSV with shape of :math:`(*, 3, H, W)`.
+ image: HSV Image to be converted to HSV with shape of :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: RGB version of the image with shape of :math:`(*, 3, H, W)`.
+ RGB version of the image with shape of :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -106,10 +108,10 @@ class RgbToHsv(nn.Module):
The image data is assumed to be in the range of (0, 1).
Args:
- eps (float, optional): scalar to enforce numarical stability. Default: 1e-6.
+ eps: scalar to enforce numarical stability.
Returns:
- torch.tensor: HSV version of the image.
+ HSV version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -135,7 +137,7 @@ class HsvToRgb(nn.Module):
H channel values are assumed to be in the range 0..2pi. S and V are in the range 0..1.
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/lab.py b/kornia/color/lab.py
index 47b25fb5a..3ddd5a08e 100644
--- a/kornia/color/lab.py
+++ b/kornia/color/lab.py
@@ -15,14 +15,16 @@ https://github.com/scikit-image/scikit-image/blob/a48bf6774718c64dade4548153ae16
def rgb_to_lab(image: torch.Tensor) -> torch.Tensor:
r"""Converts a RGB image to Lab.
+ .. image:: _static/img/rgb_to_lab.png
+
The image data is assumed to be in the range of :math:`[0, 1]`. Lab
color is computed using the D65 illuminant and Observer 2.
Args:
- image (torch.Tensor): RGB Image to be converted to Lab with shape :math:`(*, 3, H, W)`.
+ image: RGB Image to be converted to Lab with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: Lab version of the image with shape :math:`(*, 3, H, W)`.
+ Lab version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -65,11 +67,11 @@ def lab_to_rgb(image: torch.Tensor, clip: bool = True) -> torch.Tensor:
r"""Converts a Lab image to RGB.
Args:
- image (torch.Tensor): Lab image to be converted to RGB with shape :math:`(*, 3, H, W)`.
- clip (bool): Whether to apply clipping to insure output RGB values in range :math:`[0, 1]`. Default is True
+ image: Lab image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ clip: Whether to apply clipping to insure output RGB values in range :math:`[0, 1]`.
Returns:
- torch.Tensor: Lab version of the image with shape :math:`(*, 3, H, W)`.
+ Lab version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -125,7 +127,7 @@ class RgbToLab(nn.Module):
color is computed using the D65 illuminant and Observer 2.
Returns:
- torch.Tensor: Lab version of the image.
+ Lab version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -152,7 +154,7 @@ class LabToRgb(nn.Module):
r"""Converts an image from Lab to RGB.
Returns:
- torch.Tensor: RGB version of the image. Range may not be in :math:`[0, 1]`.
+ RGB version of the image. Range may not be in :math:`[0, 1]`.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/luv.py b/kornia/color/luv.py
index 2a8a8fd86..7131964d2 100644
--- a/kornia/color/luv.py
+++ b/kornia/color/luv.py
@@ -17,15 +17,17 @@ https://github.com/scikit-image/scikit-image/blob/a48bf6774718c64dade4548153ae16
def rgb_to_luv(image: torch.Tensor, eps: float = 1e-12) -> torch.Tensor:
r"""Converts a RGB image to Luv.
+ .. image:: _static/img/rgb_to_luv.png
+
The image data is assumed to be in the range of :math:`[0, 1]`. Luv
color is computed using the D65 illuminant and Observer 2.
Args:
- image (torch.Tensor): RGB Image to be converted to Luv with shape :math:`(*, 3, H, W)`.
- eps (float): for numerically stability when dividing. Default: 1e-12.
+ image: RGB Image to be converted to Luv with shape :math:`(*, 3, H, W)`.
+ eps: for numerically stability when dividing.
Returns:
- torch.Tensor: Luv version of the image with shape :math:`(*, 3, H, W)`.
+ Luv version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -69,11 +71,11 @@ def luv_to_rgb(image: torch.Tensor, eps: float = 1e-12) -> torch.Tensor:
r"""Converts a Luv image to RGB.
Args:
- image (torch.Tensor): Luv image to be converted to RGB with shape :math:`(*, 3, H, W)`.
- eps (float): for numerically stability when dividing. Default: 1e-12.
+ image: Luv image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ eps: for numerically stability when dividing.
Returns:
- torch.Tensor: Luv version of the image with shape :math:`(*, 3, H, W)`.
+ Luv version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -121,7 +123,7 @@ class RgbToLuv(nn.Module):
color is computed using the D65 illuminant and Observer 2.
Returns:
- torch.Tensor: Luv version of the image.
+ Luv version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -148,7 +150,7 @@ class LuvToRgb(nn.Module):
r"""Converts an image from Luv to RGB.
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index aecda3bf9..158834290 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -7,11 +7,13 @@ import torch.nn as nn
def rgb_to_bgr(image: torch.Tensor) -> torch.Tensor:
r"""Convert a RGB image to BGR.
+ .. image:: _static/img/rgb_to_bgr.png
+
Args:
- image (torch.Tensor): RGB Image to be converted to BGRof of shape :math:`(*,3,H,W)`.
+ image: RGB Image to be converted to BGRof of shape :math:`(*,3,H,W)`.
Returns:
- torch.Tensor: BGR version of the image with shape of shape :math:`(*,3,H,W)`.
+ BGR version of the image with shape of shape :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -30,10 +32,10 @@ def bgr_to_rgb(image: torch.Tensor) -> torch.Tensor:
r"""Convert a BGR image to RGB.
Args:
- image (torch.Tensor): BGR Image to be converted to BGR of shape :math:`(*,3,H,W)`.
+ image: BGR Image to be converted to BGR of shape :math:`(*,3,H,W)`.
Returns:
- torch.Tensor: RGB version of the image with shape of shape :math:`(*,3,H,W)`.
+ RGB version of the image with shape of shape :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -54,12 +56,12 @@ def rgb_to_rgba(image: torch.Tensor, alpha_val: Union[float, torch.Tensor]) -> t
r"""Convert an image from RGB to RGBA.
Args:
- image (torch.Tensor): RGB Image to be converted to RGBA of shape :math:`(*,3,H,W)`.
+ image: RGB Image to be converted to RGBA of shape :math:`(*,3,H,W)`.
alpha_val (float, torch.Tensor): A float number for the alpha value or a tensor
of shape :math:`(*,1,H,W)`.
Returns:
- torch.Tensor: RGBA version of the image with shape :math:`(*,4,H,W)`.
+ RGBA version of the image with shape :math:`(*,4,H,W)`.
.. note:: The current functionality is NOT supported by Torchscript.
@@ -91,12 +93,12 @@ def bgr_to_rgba(image: torch.Tensor, alpha_val: Union[float, torch.Tensor]) -> t
r"""Convert an image from BGR to RGBA.
Args:
- image (torch.Tensor): BGR Image to be converted to RGBA of shape :math:`(*,3,H,W)`.
- alpha_val (float, torch.Tensor): A float number for the alpha value or a tensor
+ image: BGR Image to be converted to RGBA of shape :math:`(*,3,H,W)`.
+ alpha_val: A float number for the alpha value or a tensor
of shape :math:`(*,1,H,W)`.
Returns:
- torch.Tensor: RGBA version of the image with shape :math:`(*,4,H,W)`.
+ RGBA version of the image with shape :math:`(*,4,H,W)`.
.. note:: The current functionality is NOT supported by Torchscript.
@@ -122,10 +124,10 @@ def rgba_to_rgb(image: torch.Tensor) -> torch.Tensor:
r"""Convert an image from RGBA to RGB.
Args:
- image (torch.Tensor): RGBA Image to be converted to RGB of shape :math:`(*,4,H,W)`.
+ image: RGBA Image to be converted to RGB of shape :math:`(*,4,H,W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*,3,H,W)`.
+ RGB version of the image with shape :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 4, 4, 5)
@@ -153,10 +155,10 @@ def rgba_to_bgr(image: torch.Tensor) -> torch.Tensor:
r"""Convert an image from RGBA to BGR.
Args:
- image (torch.Tensor): RGBA Image to be converted to BGR of shape :math:`(*,4,H,W)`.
+ image: RGBA Image to be converted to BGR of shape :math:`(*,4,H,W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*,3,H,W)`.
+ RGB version of the image with shape :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 4, 4, 5)
@@ -176,11 +178,13 @@ def rgba_to_bgr(image: torch.Tensor) -> torch.Tensor:
def rgb_to_linear_rgb(image: torch.Tensor) -> torch.Tensor:
r"""Convert an sRGB image to linear RGB. Used in colorspace conversions.
+ .. image:: _static/img/rgb_to_linear_rgb.png
+
Args:
- image (torch.Tensor): sRGB Image to be converted to linear RGB of shape :math:`(*,3,H,W)`.
+ image: sRGB Image to be converted to linear RGB of shape :math:`(*,3,H,W)`.
Returns:
- torch.Tensor: linear RGB version of the image with shape of :math:`(*,3,H,W)`.
+ linear RGB version of the image with shape of :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -202,10 +206,10 @@ def linear_rgb_to_rgb(image: torch.Tensor) -> torch.Tensor:
r"""Convert a linear RGB image to sRGB. Used in colorspace conversions.
Args:
- image (torch.Tensor): linear RGB Image to be converted to sRGB of shape :math:`(*,3,H,W)`.
+ image: linear RGB Image to be converted to sRGB of shape :math:`(*,3,H,W)`.
Returns:
- torch.Tensor: sRGB version of the image with shape of shape :math:`(*,3,H,W)`.
+ sRGB version of the image with shape of shape :math:`(*,3,H,W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -232,7 +236,7 @@ class BgrToRgb(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -254,7 +258,7 @@ class RgbToBgr(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: BGR version of the image.
+ BGR version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -276,7 +280,7 @@ class RgbToRgba(nn.Module):
Add an alpha channel to existing RGB image.
Args:
- alpha_val (float, torch.Tensor): A float number for the alpha value or a tensor
+ alpha_val: A float number for the alpha value or a tensor
of shape :math:`(*,1,H,W)`.
Returns:
@@ -308,11 +312,11 @@ class BgrToRgba(nn.Module):
Add an alpha channel to existing RGB image.
Args:
- alpha_val (float, torch.Tensor): A float number for the alpha value or a tensor
+ alpha_val: A float number for the alpha value or a tensor
of shape :math:`(*,1,H,W)`.
Returns:
- torch.Tensor: RGBA version of the image with shape :math:`(*,4,H,W)`.
+ RGBA version of the image with shape :math:`(*,4,H,W)`.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -340,7 +344,7 @@ class RgbaToRgb(nn.Module):
Remove an alpha channel from RGB image.
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 4, H, W)`
@@ -362,7 +366,7 @@ class RgbaToBgr(nn.Module):
Remove an alpha channel from BGR image.
Returns:
- torch.Tensor: BGR version of the image.
+ BGR version of the image.
Shape:
- image: :math:`(*, 4, H, W)`
@@ -385,7 +389,7 @@ class RgbToLinearRgb(nn.Module):
The image data is assumed to be in the range of :math:`[0, 1]`
Returns:
- torch.Tensor: Linear RGB version of the image.
+ Linear RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -414,7 +418,7 @@ class LinearRgbToRgb(nn.Module):
Applies gamma correction to linear RGB values, at the end of colorspace conversions, to get sRGB.
Returns:
- torch.Tensor: sRGB version of the image.
+ sRGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/xyz.py b/kornia/color/xyz.py
index 3122c186b..386f6a1fc 100644
--- a/kornia/color/xyz.py
+++ b/kornia/color/xyz.py
@@ -5,11 +5,13 @@ import torch.nn as nn
def rgb_to_xyz(image: torch.Tensor) -> torch.Tensor:
r"""Converts a RGB image to XYZ.
+ .. image:: _static/img/rgb_to_xyz.png
+
Args:
- image (torch.Tensor): RGB Image to be converted to XYZ with shape :math:`(*, 3, H, W)`.
+ image: RGB Image to be converted to XYZ with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: XYZ version of the image with shape :math:`(*, 3, H, W)`.
+ XYZ version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -38,10 +40,10 @@ def xyz_to_rgb(image: torch.Tensor) -> torch.Tensor:
r"""Converts a XYZ image to RGB.
Args:
- image (torch.Tensor): XYZ Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ image: XYZ Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*, 3, H, W)`.
+ RGB version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -72,7 +74,7 @@ class RgbToXyz(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: XYZ version of the image.
+ XYZ version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -95,7 +97,7 @@ class XyzToRgb(nn.Module):
r"""Converts an image from XYZ to RGB.
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/ycbcr.py b/kornia/color/ycbcr.py
index dd98acd9e..53462ae1d 100644
--- a/kornia/color/ycbcr.py
+++ b/kornia/color/ycbcr.py
@@ -5,11 +5,13 @@ import torch.nn as nn
def rgb_to_ycbcr(image: torch.Tensor) -> torch.Tensor:
r"""Convert an RGB image to YCbCr.
+ .. image:: _static/img/rgb_to_ycbcr.png
+
Args:
- image (torch.Tensor): RGB Image to be converted to YCbCr with shape :math:`(*, 3, H, W)`.
+ image: RGB Image to be converted to YCbCr with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: YCbCr version of the image with shape :math:`(*, 3, H, W)`.
+ YCbCr version of the image with shape :math:`(*, 3, H, W)`.
Examples:
>>> input = torch.rand(2, 3, 4, 5)
@@ -38,10 +40,10 @@ def ycbcr_to_rgb(image: torch.Tensor) -> torch.Tensor:
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): YCbCr Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ image: YCbCr Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*, 3, H, W)`.
+ RGB version of the image with shape :math:`(*, 3, H, W)`.
Examples:
>>> input = torch.rand(2, 3, 4, 5)
@@ -73,7 +75,7 @@ class RgbToYcbcr(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: YCbCr version of the image.
+ YCbCr version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -95,7 +97,7 @@ class YcbcrToRgb(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py
index 347337f31..043445a3d 100644
--- a/kornia/color/yuv.py
+++ b/kornia/color/yuv.py
@@ -5,13 +5,15 @@ import torch.nn as nn
def rgb_to_yuv(image: torch.Tensor) -> torch.Tensor:
r"""Convert an RGB image to YUV.
+ .. image:: _static/img/rgb_to_yuv.png
+
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`.
+ image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: YUV version of the image with shape :math:`(*, 3, H, W)`.
+ YUV version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -42,10 +44,10 @@ def yuv_to_rgb(image: torch.Tensor) -> torch.Tensor:
The image data is assumed to be in the range of (0, 1).
Args:
- image (torch.Tensor): YUV Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
+ image: YUV Image to be converted to RGB with shape :math:`(*, 3, H, W)`.
Returns:
- torch.Tensor: RGB version of the image with shape :math:`(*, 3, H, W)`.
+ RGB version of the image with shape :math:`(*, 3, H, W)`.
Example:
>>> input = torch.rand(2, 3, 4, 5)
@@ -76,7 +78,7 @@ class RgbToYuv(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: YUV version of the image.
+ YUV version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
@@ -101,7 +103,7 @@ class YuvToRgb(nn.Module):
The image data is assumed to be in the range of (0, 1).
Returns:
- torch.Tensor: RGB version of the image.
+ RGB version of the image.
Shape:
- image: :math:`(*, 3, H, W)`
diff --git a/readthedocs.yml b/readthedocs.yml
index 87fa516b0..5b4e0add0 100644
--- a/readthedocs.yml
+++ b/readthedocs.yml
@@ -1,5 +1,8 @@
-build:
- image: latest
+version: 2
python:
- version: 3.6
+ version: 3.7
+ install:
+ - requirements: docs/requirements.txt
+ - method: pip
+ path: .