|
3 | 3 | :mod:`colour.models.rgb.transfer_functions.gamma` module.
|
4 | 4 | """
|
5 | 5 |
|
6 |
| - |
7 | 6 | import numpy as np
|
8 | 7 |
|
9 | 8 | from colour.constants import TOLERANCE_ABSOLUTE_TESTS
|
10 | 9 | from colour.models.rgb.transfer_functions import gamma_function
|
| 10 | +from colour.models.rgb.transfer_functions.gamma import GammaFunction |
11 | 11 | from colour.utilities import ignore_numpy_errors
|
12 | 12 |
|
13 | 13 | __author__ = "Colour Developers"
|
|
22 | 22 | ]
|
23 | 23 |
|
24 | 24 |
|
| 25 | +class TestGammaFunctionClass: |
| 26 | + def test_gamma_function_class(self): |
| 27 | + """ |
| 28 | + Test :func:`colour.models.rgb.transfer_functions.gamma.\ |
| 29 | + gamma_function` definition. |
| 30 | + """ |
| 31 | + |
| 32 | + np.testing.assert_allclose( |
| 33 | + GammaFunction(2.2)(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS |
| 34 | + ) |
| 35 | + |
| 36 | + np.testing.assert_allclose( |
| 37 | + GammaFunction(2.2)(0.18), |
| 38 | + 0.022993204992707, |
| 39 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 40 | + ) |
| 41 | + |
| 42 | + np.testing.assert_allclose( |
| 43 | + GammaFunction(1.0 / 2.2)(0.022993204992707), |
| 44 | + 0.18, |
| 45 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 46 | + ) |
| 47 | + |
| 48 | + np.testing.assert_allclose( |
| 49 | + GammaFunction(2.0)(-0.18), |
| 50 | + 0.0323999999999998, |
| 51 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 52 | + ) |
| 53 | + |
| 54 | + np.testing.assert_array_equal(GammaFunction(2.2)(-0.18), np.nan) |
| 55 | + |
| 56 | + np.testing.assert_allclose( |
| 57 | + GammaFunction(2.2, "Mirror")(-0.18), |
| 58 | + -0.022993204992707, |
| 59 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 60 | + ) |
| 61 | + |
| 62 | + np.testing.assert_allclose( |
| 63 | + GammaFunction(2.2, "Preserve")(-0.18), |
| 64 | + -0.18, |
| 65 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 66 | + ) |
| 67 | + |
| 68 | + np.testing.assert_allclose( |
| 69 | + GammaFunction(2.2, "Clamp")(-0.18), |
| 70 | + 0, |
| 71 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 72 | + ) |
| 73 | + |
| 74 | + np.testing.assert_array_equal(GammaFunction(-2.2)(-0.18), np.nan) |
| 75 | + |
| 76 | + np.testing.assert_allclose( |
| 77 | + GammaFunction(-2.2, "Mirror")(0.0), |
| 78 | + 0.0, |
| 79 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 80 | + ) |
| 81 | + |
| 82 | + np.testing.assert_allclose( |
| 83 | + GammaFunction(2.2, "Preserve")(0.0), |
| 84 | + 0.0, |
| 85 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 86 | + ) |
| 87 | + |
| 88 | + np.testing.assert_allclose( |
| 89 | + GammaFunction(2.2, "Clamp")(0.0), 0, atol=TOLERANCE_ABSOLUTE_TESTS |
| 90 | + ) |
| 91 | + |
| 92 | + def test_n_dimensional_gamma_function(self): |
| 93 | + """ |
| 94 | + Test :func:`colour.models.rgb.transfer_functions.gamma.\ |
| 95 | +gamma_function` definition n-dimensional arrays support. |
| 96 | + """ |
| 97 | + |
| 98 | + a = 0.18 |
| 99 | + a_p = GammaFunction(2.2)(a) |
| 100 | + |
| 101 | + a = np.tile(a, 6) |
| 102 | + a_p = np.tile(a_p, 6) |
| 103 | + np.testing.assert_allclose( |
| 104 | + GammaFunction(2.2)(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 105 | + ) |
| 106 | + |
| 107 | + a = np.reshape(a, (2, 3)) |
| 108 | + a_p = np.reshape(a_p, (2, 3)) |
| 109 | + np.testing.assert_allclose( |
| 110 | + GammaFunction(2.2)(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 111 | + ) |
| 112 | + |
| 113 | + a = np.reshape(a, (2, 3, 1)) |
| 114 | + a_p = np.reshape(a_p, (2, 3, 1)) |
| 115 | + np.testing.assert_allclose( |
| 116 | + GammaFunction(2.2)(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 117 | + ) |
| 118 | + |
| 119 | + a = -0.18 |
| 120 | + a_p = -0.022993204992707 |
| 121 | + np.testing.assert_allclose( |
| 122 | + GammaFunction(2.2, "Mirror")(a), |
| 123 | + a_p, |
| 124 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 125 | + ) |
| 126 | + |
| 127 | + a = np.tile(a, 6) |
| 128 | + a_p = np.tile(a_p, 6) |
| 129 | + np.testing.assert_allclose( |
| 130 | + GammaFunction(2.2, "Mirror")(a), |
| 131 | + a_p, |
| 132 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 133 | + ) |
| 134 | + |
| 135 | + a = np.reshape(a, (2, 3)) |
| 136 | + a_p = np.reshape(a_p, (2, 3)) |
| 137 | + np.testing.assert_allclose( |
| 138 | + GammaFunction(2.2, "Mirror")(a), |
| 139 | + a_p, |
| 140 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 141 | + ) |
| 142 | + |
| 143 | + a = np.reshape(a, (2, 3, 1)) |
| 144 | + a_p = np.reshape(a_p, (2, 3, 1)) |
| 145 | + np.testing.assert_allclose( |
| 146 | + GammaFunction(2.2, "Mirror")(a), |
| 147 | + a_p, |
| 148 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 149 | + ) |
| 150 | + |
| 151 | + a = -0.18 |
| 152 | + a_p = -0.18 |
| 153 | + np.testing.assert_allclose( |
| 154 | + GammaFunction(2.2, "Preserve")(a), |
| 155 | + a_p, |
| 156 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 157 | + ) |
| 158 | + |
| 159 | + a = np.tile(a, 6) |
| 160 | + a_p = np.tile(a_p, 6) |
| 161 | + np.testing.assert_allclose( |
| 162 | + GammaFunction(2.2, "Preserve")(a), |
| 163 | + a_p, |
| 164 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 165 | + ) |
| 166 | + |
| 167 | + a = np.reshape(a, (2, 3)) |
| 168 | + a_p = np.reshape(a_p, (2, 3)) |
| 169 | + np.testing.assert_allclose( |
| 170 | + GammaFunction(2.2, "Preserve")(a), |
| 171 | + a_p, |
| 172 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 173 | + ) |
| 174 | + |
| 175 | + a = np.reshape(a, (2, 3, 1)) |
| 176 | + a_p = np.reshape(a_p, (2, 3, 1)) |
| 177 | + np.testing.assert_allclose( |
| 178 | + GammaFunction(2.2, "Preserve")(a), |
| 179 | + a_p, |
| 180 | + atol=TOLERANCE_ABSOLUTE_TESTS, |
| 181 | + ) |
| 182 | + |
| 183 | + a = -0.18 |
| 184 | + a_p = 0.0 |
| 185 | + np.testing.assert_allclose( |
| 186 | + GammaFunction(2.2, "Clamp")(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 187 | + ) |
| 188 | + |
| 189 | + a = np.tile(a, 6) |
| 190 | + a_p = np.tile(a_p, 6) |
| 191 | + np.testing.assert_allclose( |
| 192 | + GammaFunction(2.2, "Clamp")(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 193 | + ) |
| 194 | + |
| 195 | + a = np.reshape(a, (2, 3)) |
| 196 | + a_p = np.reshape(a_p, (2, 3)) |
| 197 | + np.testing.assert_allclose( |
| 198 | + GammaFunction(2.2, "Clamp")(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 199 | + ) |
| 200 | + |
| 201 | + a = np.reshape(a, (2, 3, 1)) |
| 202 | + a_p = np.reshape(a_p, (2, 3, 1)) |
| 203 | + np.testing.assert_allclose( |
| 204 | + GammaFunction(2.2, "Clamp")(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS |
| 205 | + ) |
| 206 | + |
| 207 | + @ignore_numpy_errors |
| 208 | + def test_nan_gamma_function(self): |
| 209 | + """ |
| 210 | + Test :func:`colour.models.rgb.transfer_functions.gamma.\ |
| 211 | +gamma_function` definition nan support. |
| 212 | + """ |
| 213 | + |
| 214 | + cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] |
| 215 | + GammaFunction(cases)(cases) |
| 216 | + |
| 217 | + |
25 | 218 | class TestGammaFunction:
|
26 | 219 | """
|
27 | 220 | Define :func:`colour.models.rgb.transfer_functions.gamma.gamma_function`
|
|
0 commit comments