Coverage for colour/models/rgb/transfer_functions/tests/test_leica_l_log.py: 100%
71 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""
2Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\
3leica_l_log` module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import log_decoding_LLog, log_encoding_LLog
10from colour.utilities import domain_range_scale, ignore_numpy_errors
12__author__ = "Colour Developers"
13__copyright__ = "Copyright 2013 Colour Developers"
14__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
15__maintainer__ = "Colour Developers"
16__email__ = "colour-developers@colour-science.org"
17__status__ = "Production"
19__all__ = [
20 "TestLogEncoding_LLog",
21 "TestLogDecoding_LLog",
22]
25class TestLogEncoding_LLog:
26 """
27 Define :func:`colour.models.rgb.transfer_functions.leica_l_log.\
28log_encoding_LLog` definition unit tests methods.
29 """
31 def test_log_encoding_LLog(self) -> None:
32 """
33 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
34log_encoding_LLog` definition.
35 """
37 np.testing.assert_allclose(
38 log_encoding_LLog(0.0),
39 0.089999999999999,
40 atol=TOLERANCE_ABSOLUTE_TESTS,
41 )
43 np.testing.assert_allclose(
44 log_encoding_LLog(0.18),
45 0.435313904043927,
46 atol=TOLERANCE_ABSOLUTE_TESTS,
47 )
49 np.testing.assert_allclose(
50 log_encoding_LLog(0.18, 12),
51 0.435313904043927,
52 atol=TOLERANCE_ABSOLUTE_TESTS,
53 )
55 np.testing.assert_allclose(
56 log_encoding_LLog(0.18, 10, False),
57 0.4353037943344028,
58 atol=TOLERANCE_ABSOLUTE_TESTS,
59 )
61 np.testing.assert_allclose(
62 log_encoding_LLog(0.18, 10, False, False),
63 0.421586960452824,
64 atol=TOLERANCE_ABSOLUTE_TESTS,
65 )
67 np.testing.assert_allclose(
68 log_encoding_LLog(1.0),
69 0.631797439630121,
70 atol=TOLERANCE_ABSOLUTE_TESTS,
71 )
73 def test_n_dimensional_log_encoding_LLog(self) -> None:
74 """
75 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
76log_encoding_LLog` definition n-dimensional arrays support.
77 """
79 y = 0.18
80 x = log_encoding_LLog(y)
82 y = np.tile(y, 6)
83 x = np.tile(x, 6)
84 np.testing.assert_allclose(
85 log_encoding_LLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
86 )
88 y = np.reshape(y, (2, 3))
89 x = np.reshape(x, (2, 3))
90 np.testing.assert_allclose(
91 log_encoding_LLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
92 )
94 y = np.reshape(y, (2, 3, 1))
95 x = np.reshape(x, (2, 3, 1))
96 np.testing.assert_allclose(
97 log_encoding_LLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
98 )
100 def test_domain_range_scale_log_encoding_LLog(self) -> None:
101 """
102 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
103log_encoding_LLog` definition domain and range scale support.
104 """
106 y = 0.18
107 x = log_encoding_LLog(y)
109 d_r = (("reference", 1), ("1", 1), ("100", 100))
110 for scale, factor in d_r:
111 with domain_range_scale(scale):
112 np.testing.assert_allclose(
113 log_encoding_LLog(y * factor),
114 x * factor,
115 atol=TOLERANCE_ABSOLUTE_TESTS,
116 )
118 @ignore_numpy_errors
119 def test_nan_log_encoding_LLog(self) -> None:
120 """
121 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
122log_encoding_LLog` definition nan support.
123 """
125 log_encoding_LLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
128class TestLogDecoding_LLog:
129 """
130 Define :func:`colour.models.rgb.transfer_functions.leica_l_log.\
131log_decoding_LLog` definition unit tests methods.
132 """
134 def test_log_decoding_LLog(self) -> None:
135 """
136 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
137log_decoding_LLog` definition.
138 """
140 np.testing.assert_allclose(
141 log_decoding_LLog(0.089999999999999),
142 0.0,
143 atol=TOLERANCE_ABSOLUTE_TESTS,
144 )
146 np.testing.assert_allclose(
147 log_decoding_LLog(0.435313904043927),
148 0.18,
149 atol=TOLERANCE_ABSOLUTE_TESTS,
150 )
152 np.testing.assert_allclose(
153 log_decoding_LLog(0.435313904043927, 12),
154 0.18,
155 atol=TOLERANCE_ABSOLUTE_TESTS,
156 )
158 np.testing.assert_allclose(
159 log_decoding_LLog(0.4353037943344028, 10, False),
160 0.18,
161 atol=TOLERANCE_ABSOLUTE_TESTS,
162 )
164 np.testing.assert_allclose(
165 log_decoding_LLog(0.421586960452824, 10, False, False),
166 0.18,
167 atol=TOLERANCE_ABSOLUTE_TESTS,
168 )
170 np.testing.assert_allclose(
171 log_decoding_LLog(0.631797439630121),
172 1.0,
173 atol=TOLERANCE_ABSOLUTE_TESTS,
174 )
176 def test_n_dimensional_log_decoding_LLog(self) -> None:
177 """
178 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
179log_decoding_LLog` definition n-dimensional arrays support.
180 """
182 x = 0.435313904043927
183 y = log_decoding_LLog(x)
185 x = np.tile(x, 6)
186 y = np.tile(y, 6)
187 np.testing.assert_allclose(
188 log_decoding_LLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
189 )
191 x = np.reshape(x, (2, 3))
192 y = np.reshape(y, (2, 3))
193 np.testing.assert_allclose(
194 log_decoding_LLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
195 )
197 x = np.reshape(x, (2, 3, 1))
198 y = np.reshape(y, (2, 3, 1))
199 np.testing.assert_allclose(
200 log_decoding_LLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
201 )
203 def test_domain_range_scale_log_decoding_LLog(self) -> None:
204 """
205 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
206log_decoding_LLog` definition domain and range scale support.
207 """
209 x = 0.435313904043927
210 y = log_decoding_LLog(x)
212 d_r = (("reference", 1), ("1", 1), ("100", 100))
213 for scale, factor in d_r:
214 with domain_range_scale(scale):
215 np.testing.assert_allclose(
216 log_decoding_LLog(x * factor),
217 y * factor,
218 atol=TOLERANCE_ABSOLUTE_TESTS,
219 )
221 @ignore_numpy_errors
222 def test_nan_log_decoding_LLog(self) -> None:
223 """
224 Test :func:`colour.models.rgb.transfer_functions.leica_l_log.\
225log_decoding_LLog` definition nan support.
226 """
228 log_decoding_LLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))