Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

improve kornia.enhance docs and coverage (#805)

Edgar Ribac0a5c1616882
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index a85ac768a..50f61524f 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -70,7 +70,7 @@ 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 woth shape :math:`(*, 3, H, W)`.
+ image (torch.Tensor): 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)`.
diff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.py
index 92934182d..f559a5cce 100644
--- a/kornia/enhance/adjust.py
+++ b/kornia/enhance/adjust.py
@@ -33,8 +33,6 @@ __all__ = [
def adjust_saturation_raw(input: torch.Tensor, saturation_factor: Union[float, torch.Tensor]) -> torch.Tensor:
r"""Adjust color saturation of an image. Expecting input to be in hsv format already.
-
- See :class:`~kornia.color.AdjustSaturation` for details.
"""
if not isinstance(input, torch.Tensor):
@@ -76,8 +74,7 @@ def adjust_saturation(input: torch.Tensor, saturation_factor: Union[float, torch
Args:
input (torch.Tensor): Image/Tensor to be adjusted in the shape of :math:`(*, 3, H, W)`.
saturation_factor (Union[float, torch.Tensor]): 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.
+ and white image, 1 will give the original image while 2 will enhance the saturation by a factor of 2.
Return:
torch.Tensor: Adjusted image in the shape of :math:`(*, 3, H, W)`.
@@ -118,8 +115,6 @@ def adjust_saturation(input: torch.Tensor, saturation_factor: Union[float, torch
def adjust_hue_raw(input: torch.Tensor, hue_factor: Union[float, torch.Tensor]) -> torch.Tensor:
r"""Adjust hue of an image. Expecting input to be in hsv format already.
-
- See :class:`~kornia.color.AdjustHue` for details.
"""
if not isinstance(input, torch.Tensor):
@@ -759,8 +754,7 @@ class AdjustSaturation(nn.Module):
Args:
saturation_factor (Union[float, torch.Tensor]): 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.
+ and white image, 1 will give the original image while 2 will enhance the saturation by a factor of 2.
Shape:
- Input: Image/Tensor to be adjusted in the shape of :math:`(*, 3, H, W)`.
diff --git a/kornia/enhance/core.py b/kornia/enhance/core.py
index 00c4c5a16..24edbc88e 100644
--- a/kornia/enhance/core.py
+++ b/kornia/enhance/core.py
@@ -68,9 +68,9 @@ class AddWeighted(nn.Module):
gamma (float): scalar added to each sum.
Shape:
- Input1: Tensor of shape :math:`(B, C, H, W)`.
- Input2: Tensor of shape :math:`(B, C, H, W)`.
- Output: Weighted tensor of shape :math:`(B, C, H, W)`.
+ - Input1: Tensor of shape :math:`(B, C, H, W)`.
+ - Input2: Tensor of shape :math:`(B, C, H, W)`.
+ - Output: Weighted tensor of shape :math:`(B, C, H, W)`.
Example:
>>> input1 = torch.rand(1, 1, 5, 5)
diff --git a/kornia/enhance/histogram.py b/kornia/enhance/histogram.py
index 71ed7fe8c..968120df2 100644
--- a/kornia/enhance/histogram.py
+++ b/kornia/enhance/histogram.py
@@ -149,7 +149,7 @@ def histogram2d(
epsilon (float): A scalar, for numerical stability. Default: 1e-10.
Returns:
- torch.Tensor: Computed histogram of shape :math:`(B, N_{bins})`.
+ torch.Tensor: Computed histogram of shape :math:`(B, N_{bins}), N_{bins})`.
Examples:
>>> x1 = torch.rand(2, 32)
diff --git a/kornia/enhance/normalize.py b/kornia/enhance/normalize.py
index 9840d519c..2418be824 100644
--- a/kornia/enhance/normalize.py
+++ b/kornia/enhance/normalize.py
@@ -21,7 +21,7 @@ class Normalize(nn.Module):
.. math::
\text{input[channel] = (input[channel] - mean[channel]) / std[channel]}
- Where `mean` is :math:`(M_1,...,M_n)` and `std` :math:`(S_1,..,S_n)` for `n` channels,
+ Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
mean (Union[torch.Tensor, float]): Mean for each channel.
@@ -68,7 +68,7 @@ def normalize(
.. math::
\text{input[channel] = (input[channel] - mean[channel]) / std[channel]}
- Where `mean` is :math:`(M_1,...,M_n)` and `std` :math:`(S_1,..,S_n)` for `n` channels,
+ Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
data (torch.Tensor): Image tensor of size :math:`(*, C, H, W)`.
@@ -133,7 +133,7 @@ class Denormalize(nn.Module):
.. math::
\text{input[channel] = (input[channel] * mean[channel]) + std[channel]}
- Where `mean` is :math:`(M_1,...,M_n)` and `std` :math:`(S_1,..,S_n)` for `n` channels,
+ Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
mean (Union[torch.Tensor, float]): Mean for each channel.
@@ -180,7 +180,7 @@ def denormalize(
.. math::
\text{input[channel] = (input[channel] * mean[channel]) + std[channel]}
- Where `mean` is :math:`(M_1,...,M_n)` and `std` :math:`(S_1,..,S_n)` for `n` channels,
+ Where `mean` is :math:`(M_1, ..., M_n)` and `std` :math:`(S_1, ..., S_n)` for `n` channels,
Args:
input (torch.Tensor): Image tensor of size :math:`(*, C, H, W)`.
diff --git a/test/enhance/test_adjust.py b/test/enhance/test_adjust.py
index 634156ab3..33aa06107 100644
--- a/test/enhance/test_adjust.py
+++ b/test/enhance/test_adjust.py
@@ -734,9 +734,13 @@ class TestSharpness(BaseTester):
assert isinstance(TestSharpness.f(img, 0.8), torch.Tensor)
@pytest.mark.parametrize("batch_size, height, width, factor", [
- (1, 4, 5, 0.8), (2, 4, 5, 0.8),
- (1, 4, 5, torch.tensor(0.8)), (2, 4, 5, torch.tensor(0.8)),
- (2, 4, 5, torch.tensor([0.8, 0.7]))])
+ (1, 4, 5, 0.0),
+ (1, 4, 5, 0.8),
+ (2, 4, 5, 0.8),
+ (1, 4, 5, torch.tensor(0.8)),
+ (2, 4, 5, torch.tensor(0.8)),
+ (2, 4, 5, torch.tensor([0.8, 0.7]))
+ ])
@pytest.mark.parametrize("channels", [1, 3, 5])
def test_cardinality(self, batch_size, channels, height, width, factor, device, dtype):
inputs = torch.ones(batch_size, channels, height, width, device=device, dtype=dtype)
@@ -837,15 +841,19 @@ class TestSolarize(BaseTester):
img = torch.rand(B, C, H, W, device=device, dtype=dtype)
assert isinstance(TestSolarize.f(img, 0.8), torch.Tensor)
- # TODO(jian): verify thresholds test and include addtions
- @pytest.mark.parametrize("batch_size, height, width, thresholds", [
- (1, 4, 5, 0.8), (2, 4, 5, 0.8),
- (1, 4, 5, torch.tensor(0.8)), (2, 4, 5, torch.tensor(0.8)),
- (2, 4, 5, torch.tensor([0.8, 0.7]))])
+ @pytest.mark.parametrize("batch_size, height, width, thresholds, additions", [
+ (1, 4, 5, 0.8, None),
+ (1, 4, 5, 0.8, 0.4),
+ (2, 4, 5, 0.8, None),
+ (1, 4, 5, torch.tensor(0.8), None),
+ (2, 4, 5, torch.tensor(0.8), None),
+ (2, 4, 5, torch.tensor([0.8, 0.7]), None),
+ (2, 4, 5, torch.tensor([0.8, 0.7]), torch.tensor([0., 0.4]))
+ ])
@pytest.mark.parametrize("channels", [1, 3, 5])
- def test_cardinality(self, batch_size, channels, height, width, thresholds, device, dtype):
+ def test_cardinality(self, batch_size, channels, height, width, thresholds, additions, device, dtype):
inputs = torch.ones(batch_size, channels, height, width, device=device, dtype=dtype)
- assert TestSolarize.f(inputs, thresholds).shape == torch.Size([batch_size, channels, height, width])
+ assert TestSolarize.f(inputs, thresholds, additions).shape == torch.Size([batch_size, channels, height, width])
# TODO(jian): add better assertions
def test_exception(self, device, dtype):
@@ -914,9 +922,14 @@ class TestPosterize(BaseTester):
assert isinstance(TestPosterize.f(img, 8), torch.Tensor)
@pytest.mark.parametrize("batch_size, height, width, bits", [
- (1, 4, 5, 8), (2, 4, 5, 0),
- (1, 4, 5, torch.tensor(8)), (2, 4, 5, torch.tensor(8)),
- (2, 4, 5, torch.tensor([0, 8]))])
+ (1, 4, 5, 8),
+ (2, 4, 5, 1),
+ (2, 4, 5, 0),
+ (1, 4, 5, torch.tensor(8)),
+ (2, 4, 5, torch.tensor(8)),
+ (2, 4, 5, torch.tensor([0, 8])),
+ (3, 4, 5, torch.tensor([0, 1, 8]))
+ ])
@pytest.mark.parametrize("channels", [1, 3, 5])
def test_cardinality(self, batch_size, channels, height, width, bits, device, dtype):
inputs = torch.ones(batch_size, channels, height, width, device=device, dtype=dtype)