Coverage for models/rgb/tests/test_hanbury2003.py: 100%
65 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""Defines unit tests for :mod:`colour.models.rgb.hanbury2003` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models.rgb import IHLS_to_RGB, RGB_to_IHLS
11from colour.utilities import domain_range_scale, ignore_numpy_errors
13__author__ = "Colour Developers"
14__copyright__ = "Copyright 2013 Colour Developers"
15__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
16__maintainer__ = "Colour Developers"
17__email__ = "colour-developers@colour-science.org"
18__status__ = "Production"
20__all__ = [
21 "TestRGB_to_IHLS",
22 "TestIHLS_to_RGB",
23]
26class TestRGB_to_IHLS:
27 """
28 Define :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition unit
29 tests methods.
30 """
32 def test_RGB_to_IHLS(self) -> None:
33 """Test :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition."""
35 np.testing.assert_allclose(
36 RGB_to_IHLS(np.array([0.45620519, 0.03081071, 0.04091952])),
37 np.array([6.26236117, 0.12197943, 0.42539448]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 np.testing.assert_allclose(
42 RGB_to_IHLS(np.array([0.00000000, 0.00000000, 0.00000000])),
43 np.array([0.00000000, 0.00000000, 0.00000000]),
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 RGB_to_IHLS(np.array([1.00000000, 1.00000000, 1.00000000])),
49 np.array([0.00000000, 1.00000000, 0.00000000]),
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 def test_n_dimensional_RGB_to_IHLS(self) -> None:
54 """
55 Test :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition
56 n-dimensional arrays support.
57 """
59 RGB = np.array([0.45620519, 0.03081071, 0.04091952])
60 HYS = RGB_to_IHLS(RGB)
62 RGB = np.tile(RGB, (6, 1))
63 HYS = np.tile(HYS, (6, 1))
64 np.testing.assert_allclose(RGB_to_IHLS(RGB), HYS, atol=TOLERANCE_ABSOLUTE_TESTS)
66 RGB = np.reshape(RGB, (2, 3, 3))
67 HYS = np.reshape(HYS, (2, 3, 3))
68 np.testing.assert_allclose(RGB_to_IHLS(RGB), HYS, atol=TOLERANCE_ABSOLUTE_TESTS)
70 def test_domain_range_scale_RGB_to_IHLS(self) -> None:
71 """
72 Test :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition
73 domain and range scale support.
74 """
76 RGB = np.array([0.45620519, 0.03081071, 0.04091952])
77 HYS = RGB_to_IHLS(RGB)
79 d_r = (("reference", 1), ("1", 1), ("100", 100))
80 for scale, factor in d_r:
81 with domain_range_scale(scale):
82 np.testing.assert_allclose(
83 RGB_to_IHLS(RGB * factor),
84 HYS * factor,
85 atol=TOLERANCE_ABSOLUTE_TESTS,
86 )
88 @ignore_numpy_errors
89 def test_nan_RGB_to_IHLS(self) -> None:
90 """
91 Test :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition nan
92 support.
93 """
95 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
96 cases = np.array(list(set(product(cases, repeat=3))))
97 RGB_to_IHLS(cases)
100class TestIHLS_to_RGB:
101 """
102 Define :func:`colour.models.rgb.hanbury2003.RGB_to_IHLS` definition unit
103 tests methods.
104 """
106 def test_IHLS_to_RGB(self) -> None:
107 """Test :func:`colour.models.rgb.hanbury2003.IHLS_to_RGB` definition."""
109 np.testing.assert_allclose(
110 IHLS_to_RGB(np.array([6.26236117, 0.12197943, 0.42539448])),
111 np.array([0.45620519, 0.03081071, 0.04091952]),
112 atol=TOLERANCE_ABSOLUTE_TESTS,
113 )
115 np.testing.assert_allclose(
116 IHLS_to_RGB(np.array([0.00000000, 0.00000000, 0.00000000])),
117 np.array([0.00000000, 0.00000000, 0.00000000]),
118 atol=TOLERANCE_ABSOLUTE_TESTS,
119 )
121 np.testing.assert_allclose(
122 IHLS_to_RGB(np.array([0.00000000, 1.00000000, 0.00000000])),
123 np.array([1.00000000, 1.00000000, 1.00000000]),
124 atol=TOLERANCE_ABSOLUTE_TESTS,
125 )
127 def test_n_dimensional_IHLS_to_RGB(self) -> None:
128 """
129 Test :func:`colour.models.rgb.hanbury2003.IHLS_to_RGB` definition
130 n-dimensional arrays support.
131 """
133 HYS = np.array([6.26236117, 0.12197943, 0.42539448])
134 RGB = IHLS_to_RGB(HYS)
136 HYS = np.tile(HYS, (6, 1))
137 RGB = np.tile(RGB, (6, 1))
138 np.testing.assert_allclose(IHLS_to_RGB(HYS), RGB, atol=TOLERANCE_ABSOLUTE_TESTS)
140 HYS = np.reshape(HYS, (2, 3, 3))
141 RGB = np.reshape(RGB, (2, 3, 3))
142 np.testing.assert_allclose(IHLS_to_RGB(HYS), RGB, atol=TOLERANCE_ABSOLUTE_TESTS)
144 def test_domain_range_scale_IHLS_to_RGB(self) -> None:
145 """
146 Test :func:`colour.models.rgb.hanbury2003.IHLS_to_RGB` definition
147 domain and range scale support.
148 """
150 HYS = np.array([6.26236117, 0.12197943, 0.42539448])
151 RGB = IHLS_to_RGB(HYS)
153 d_r = (("reference", 1), ("1", 1), ("100", 100))
154 for scale, factor in d_r:
155 with domain_range_scale(scale):
156 np.testing.assert_allclose(
157 IHLS_to_RGB(HYS * factor),
158 RGB * factor,
159 atol=TOLERANCE_ABSOLUTE_TESTS,
160 )
162 @ignore_numpy_errors
163 def test_nan_IHLS_to_RGB(self) -> None:
164 """
165 Test :func:`colour.models.rgb.hanbury2003.IHLS_to_RGB` definition nan
166 support.
167 """
169 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
170 cases = np.array(list(set(product(cases, repeat=3))))
171 IHLS_to_RGB(cases)