Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

:boot: Improves `kornia.color` documentation (#1331)

Edgar Ribaaf3bfa7b6864
diff --git a/docs/generate_example_images.py b/docs/generate_example_images.py
index f63158608..a7c5288d5 100644
--- a/docs/generate_example_images.py
+++ b/docs/generate_example_images.py
@@ -128,7 +128,7 @@ def main():
mod = importlib.import_module("kornia.color")
color_transforms_list: dict = {
- "grayscale_to_rgb": ((), 1),
+ "grayscale_to_rgb": ((), 3),
"rgb_to_bgr": ((), 1),
"rgb_to_grayscale": ((), 1),
"rgb_to_hsv": ((), 1),
diff --git a/docs/source/color.rst b/docs/source/color.rst
index 880c0fc6f..7a283a604 100644
--- a/docs/source/color.rst
+++ b/docs/source/color.rst
@@ -5,66 +5,139 @@ kornia.color
The functions in this section perform various color space conversions.
+.. note::
+ Check a tutorial for color space conversions `here <https://kornia-tutorials.readthedocs.io/en/latest/
+ hello_world_tutorial.html>`__.
+
+
+Grayscale
+---------
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/Grayscale
+
+.. autofunction:: rgb_to_grayscale
+.. autofunction:: bgr_to_grayscale
.. autofunction:: grayscale_to_rgb
+
+.. autoclass:: GrayscaleToRgb
+.. autoclass:: RgbToGrayscale
+.. autoclass:: BgrToGrayscale
+
+RGB
+---
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/RGB_color_model
+
.. autofunction:: rgb_to_bgr
-.. autofunction:: rgb_to_grayscale
-.. autofunction:: rgb_to_hsv
-.. autofunction:: rgb_to_hls
-.. autofunction:: rgb_to_luv
-.. autofunction:: rgb_to_lab
-.. autofunction:: rgb_to_rgba
-.. autofunction:: rgb_to_xyz
-.. autofunction:: rgb_to_ycbcr
-.. autofunction:: rgb_to_yuv
+.. autofunction:: bgr_to_rgb
.. autofunction:: rgb_to_linear_rgb
.. autofunction:: linear_rgb_to_rgb
+.. autoclass:: RgbToBgr
+.. autoclass:: BgrToRgb
+
+.. autoclass:: LinearRgbToRgb
+.. autoclass:: RgbToLinearRgb
+
+RGBA
+----
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/RGBA_color_model
+
+.. autofunction:: bgr_to_rgba
+.. autofunction:: rgb_to_rgba
.. autofunction:: rgba_to_rgb
.. autofunction:: rgba_to_bgr
-.. autofunction:: bgr_to_grayscale
-.. autofunction:: bgr_to_rgb
-.. autofunction:: bgr_to_rgba
+.. autoclass:: RgbToRgba
+.. autoclass:: BgrToRgba
+.. autoclass:: RgbaToRgb
+.. autoclass:: RgbaToBgr
+
+HLS
+---
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/HSL_and_HSV
+
+.. autofunction:: rgb_to_hls
.. autofunction:: hls_to_rgb
+.. autoclass:: RgbToHls
+.. autoclass:: HlsToRgb
+
+HSV
+---
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/HSL_and_HSV
+
+.. autofunction:: rgb_to_hsv
.. autofunction:: hsv_to_rgb
-.. autofunction:: lab_to_rgb
+.. autoclass:: RgbToHsv
+.. autoclass:: HsvToRgb
+
+LUV
+---
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/CIELUV
+
+.. autofunction:: rgb_to_luv
.. autofunction:: luv_to_rgb
+.. autoclass:: RgbToLuv
+.. autoclass:: LuvToRgb
+
+Lab
+---
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/CIELAB_color_space
+
+.. autofunction:: rgb_to_lab
+.. autofunction:: lab_to_rgb
+
+.. autoclass:: RgbToLab
+.. autoclass:: LabToRgb
+
+YCbCr
+-----
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/YCbCr
+
+.. autofunction:: rgb_to_ycbcr
.. autofunction:: ycbcr_to_rgb
-.. autofunction:: yuv_to_rgb
-.. autofunction:: xyz_to_rgb
+.. autoclass:: YcbcrToRgb
+.. autoclass:: RgbToYcbcr
+YUV
+---
-Modules
--------
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/YUV
+
+.. autofunction:: rgb_to_yuv
+.. autofunction:: yuv_to_rgb
-.. autoclass:: GrayscaleToRgb
-.. autoclass:: RgbToGrayscale
-.. autoclass:: BgrToGrayscale
-.. autoclass:: RgbToHsv
-.. autoclass:: HsvToRgb
-.. autoclass:: RgbToHls
-.. autoclass:: HlsToRgb
-.. autoclass:: RgbToBgr
-.. autoclass:: BgrToRgb
.. autoclass:: RgbToYuv
.. autoclass:: YuvToRgb
-.. autoclass:: RgbToRgba
-.. autoclass:: BgrToRgba
-.. autoclass:: RgbaToRgb
-.. autoclass:: RgbaToBgr
+
+XYZ
+---
+
+.. tip::
+ Learn more: https://en.wikipedia.org/wiki/CIELUV
+
+.. autofunction:: rgb_to_xyz
+.. autofunction:: xyz_to_rgb
+
.. autoclass:: RgbToXyz
.. autoclass:: XyzToRgb
-.. autoclass:: RgbToLuv
-.. autoclass:: LuvToRgb
-.. autoclass:: YcbcrToRgb
-.. autoclass:: RgbToYcbcr
-.. autoclass:: RgbToLab
-.. autoclass:: LabToRgb
-.. autoclass:: LinearRgbToRgb
-.. autoclass:: RgbToLinearRgb
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index b73d90c54..c54866814 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -15,10 +15,6 @@ def rgb_to_bgr(image: torch.Tensor) -> torch.Tensor:
Returns:
BGR version of the image with shape of shape :math:`(*,3,H,W)`.
- .. note::
- See a working example `here <https://kornia-tutorials.readthedocs.io/en/latest/
- hello_world_tutorial.html>`__.
-
Example:
>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_bgr(input) # 2x3x4x5
@@ -41,10 +37,6 @@ def bgr_to_rgb(image: torch.Tensor) -> torch.Tensor:
Returns:
RGB version of the image with shape of shape :math:`(*,3,H,W)`.
- .. note::
- See a working example `here <https://kornia-tutorials.readthedocs.io/en/latest/
- color_conversions.html>`__.
-
Example:
>>> input = torch.rand(2, 3, 4, 5)
>>> output = bgr_to_rgb(input) # 2x3x4x5
diff --git a/test/color/test_hsv.py b/test/color/test_hsv.py
index feb82e312..01d4a6be6 100644
--- a/test/color/test_hsv.py
+++ b/test/color/test_hsv.py
@@ -98,13 +98,11 @@ class TestRgbToHsv(BaseTester):
expected = torch.zeros_like(data) # 3x5x5
assert_close(kornia.color.rgb_to_hsv(data), expected)
- @pytest.mark.grad
def test_gradcheck(self, device, dtype):
B, C, H, W = 2, 3, 4, 4
img = torch.rand(B, C, H, W, device=device, dtype=torch.float64, requires_grad=True)
assert gradcheck(kornia.color.rgb_to_hsv, (img,), raise_exception=True)
- @pytest.mark.jit
def test_jit(self, device, dtype):
B, C, H, W = 2, 3, 4, 4
img = torch.ones(B, C, H, W, device=device, dtype=dtype)
@@ -112,7 +110,6 @@ class TestRgbToHsv(BaseTester):
op_jit = torch.jit.script(op)
assert_close(op(img), op_jit(img))
- @pytest.mark.nn
def test_module(self, device, dtype):
B, C, H, W = 2, 3, 4, 4
img = torch.ones(B, C, H, W, device=device, dtype=dtype)
@@ -120,6 +117,18 @@ class TestRgbToHsv(BaseTester):
fcn = kornia.color.rgb_to_hsv
assert_close(ops(img), fcn(img))
+ def test_onnx(self, device, dtype):
+ B, C, H, W = 1, 3, 4, 4
+ img = torch.ones(B, C, H, W, device=device, dtype=dtype)
+ torch.onnx.export(
+ kornia.color.RgbToHsv(),
+ (img), # Dummy input for shape
+ "model.onnx",
+ opset_version=12,
+ do_constant_folding=True,
+ verbose=True,
+ )
+
class TestHsvToRgb(BaseTester):
def test_smoke(self, device, dtype):