Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Create test for Brightness

Pau Ribac335f163c15d
diff --git a/test/color/test_adjust.py b/test/color/test_adjust.py
new file mode 100644
index 000000000..6f644fb7c
--- /dev/null
+++ b/test/color/test_adjust.py
@@ -0,0 +1,76 @@
+import pytest
+
+import kornia
+import kornia.testing as utils # test utils
+from test.common import device_type
+
+import torch
+from torch.autograd import gradcheck
+from torch.testing import assert_allclose
+
+
+class TestAdjustColor:
+ def test_adjust_bightness_factor_zero(self):
+ # prepare input data
+ data = torch.tensor([[[1., 1.],
+ [1., 1.]],
+
+ [[.5, .5],
+ [.5, .5]],
+
+ [[.25, .25],
+ [.25, .25]]]) # 3x2x2
+
+ expected = torch.tensor([[[0., 0.],
+ [0., 0.]],
+
+ [[0., 0.],
+ [0., 0.]],
+
+ [[0., 0.],
+ [0., 0.]]]) # 3x2x2
+
+ f = kornia.color.AdjustBrightness()
+
+ assert_allclose(f(data, 0), expected)
+
+ def test_adjust_bightness_factor_one(self):
+ # prepare input data
+ data = torch.tensor([[[1., 1.],
+ [1., 1.]],
+
+ [[.5, .5],
+ [.5, .5]],
+
+ [[.25, .25],
+ [.25, .25]]]) # 3x2x2
+
+ expected = data
+
+ f = kornia.color.AdjustBrightness()
+
+ assert_allclose(f(data, 1), expected)
+
+ def test_adjust_bightness_factor_two(self):
+ # prepare input data
+ data = torch.tensor([[[1., 1.],
+ [1., 1.]],
+
+ [[.5, .5],
+ [.5, .5]],
+
+ [[.25, .25],
+ [.25, .25]]]) # 3x2x2
+
+ expected = torch.tensor([[[1., 1.],
+ [1., 1.]],
+
+ [[1., 1.],
+ [1., 1.]],
+
+ [[.5, .5],
+ [.5, .5]]]) # 3x2x2
+
+ f = kornia.color.AdjustBrightness()
+
+ assert_allclose(f(data, 2), expected)