Coverage for colour/models/rgb/transfer_functions/tests/test_panasonic_vlog.py: 100%

71 statements  

« 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.\ 

3panasonic_v_log` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import log_decoding_VLog, log_encoding_VLog 

10from colour.utilities import domain_range_scale, ignore_numpy_errors 

11 

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" 

18 

19__all__ = [ 

20 "TestLogEncoding_VLog", 

21 "TestLogDecoding_VLog", 

22] 

23 

24 

25class TestLogEncoding_VLog: 

26 """ 

27 Define :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

28log_encoding_VLog` definition unit tests methods. 

29 """ 

30 

31 def test_log_encoding_VLog(self) -> None: 

32 """ 

33 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

34log_encoding_VLog` definition. 

35 """ 

36 

37 np.testing.assert_allclose( 

38 log_encoding_VLog(0.0), 0.125, atol=TOLERANCE_ABSOLUTE_TESTS 

39 ) 

40 

41 np.testing.assert_allclose( 

42 log_encoding_VLog(0.18), 

43 0.423311448760136, 

44 atol=TOLERANCE_ABSOLUTE_TESTS, 

45 ) 

46 

47 np.testing.assert_allclose( 

48 log_encoding_VLog(0.18, 12), 

49 0.423311448760136, 

50 atol=TOLERANCE_ABSOLUTE_TESTS, 

51 ) 

52 

53 np.testing.assert_allclose( 

54 log_encoding_VLog(0.18, 10, False), 

55 0.421287228403675, 

56 atol=TOLERANCE_ABSOLUTE_TESTS, 

57 ) 

58 

59 np.testing.assert_allclose( 

60 log_encoding_VLog(0.18, 10, False, False), 

61 0.409009628526078, 

62 atol=TOLERANCE_ABSOLUTE_TESTS, 

63 ) 

64 

65 np.testing.assert_allclose( 

66 log_encoding_VLog(1.0), 

67 0.599117700158146, 

68 atol=TOLERANCE_ABSOLUTE_TESTS, 

69 ) 

70 

71 def test_n_dimensional_log_encoding_VLog(self) -> None: 

72 """ 

73 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

74log_encoding_VLog` definition n-dimensional arrays support. 

75 """ 

76 

77 L_in = 0.18 

78 V_out = log_encoding_VLog(L_in) 

79 

80 L_in = np.tile(L_in, 6) 

81 V_out = np.tile(V_out, 6) 

82 np.testing.assert_allclose( 

83 log_encoding_VLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS 

84 ) 

85 

86 L_in = np.reshape(L_in, (2, 3)) 

87 V_out = np.reshape(V_out, (2, 3)) 

88 np.testing.assert_allclose( 

89 log_encoding_VLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS 

90 ) 

91 

92 L_in = np.reshape(L_in, (2, 3, 1)) 

93 V_out = np.reshape(V_out, (2, 3, 1)) 

94 np.testing.assert_allclose( 

95 log_encoding_VLog(L_in), V_out, atol=TOLERANCE_ABSOLUTE_TESTS 

96 ) 

97 

98 def test_domain_range_scale_log_encoding_VLog(self) -> None: 

99 """ 

100 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

101log_encoding_VLog` definition domain and range scale support. 

102 """ 

103 

104 L_in = 0.18 

105 V_out = log_encoding_VLog(L_in) 

106 

107 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

108 for scale, factor in d_r: 

109 with domain_range_scale(scale): 

110 np.testing.assert_allclose( 

111 log_encoding_VLog(L_in * factor), 

112 V_out * factor, 

113 atol=TOLERANCE_ABSOLUTE_TESTS, 

114 ) 

115 

116 @ignore_numpy_errors 

117 def test_nan_log_encoding_VLog(self) -> None: 

118 """ 

119 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

120log_encoding_VLog` definition nan support. 

121 """ 

122 

123 log_encoding_VLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

124 

125 

126class TestLogDecoding_VLog: 

127 """ 

128 Define :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

129log_decoding_VLog` definition unit tests methods. 

130 """ 

131 

132 def test_log_decoding_VLog(self) -> None: 

133 """ 

134 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

135log_decoding_VLog` definition. 

136 """ 

137 

138 np.testing.assert_allclose( 

139 log_decoding_VLog(0.125), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

140 ) 

141 

142 np.testing.assert_allclose( 

143 log_decoding_VLog(0.423311448760136), 

144 0.18, 

145 atol=TOLERANCE_ABSOLUTE_TESTS, 

146 ) 

147 

148 np.testing.assert_allclose( 

149 log_decoding_VLog(0.423311448760136, 12), 

150 0.18, 

151 atol=TOLERANCE_ABSOLUTE_TESTS, 

152 ) 

153 

154 np.testing.assert_allclose( 

155 log_decoding_VLog(0.421287228403675, 10, False), 

156 0.18, 

157 atol=TOLERANCE_ABSOLUTE_TESTS, 

158 ) 

159 

160 np.testing.assert_allclose( 

161 log_decoding_VLog(0.409009628526078, 10, False, False), 

162 0.18, 

163 atol=TOLERANCE_ABSOLUTE_TESTS, 

164 ) 

165 

166 np.testing.assert_allclose( 

167 log_decoding_VLog(0.599117700158146), 

168 1.0, 

169 atol=TOLERANCE_ABSOLUTE_TESTS, 

170 ) 

171 

172 def test_n_dimensional_log_decoding_VLog(self) -> None: 

173 """ 

174 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

175log_decoding_VLog` definition n-dimensional arrays support. 

176 """ 

177 

178 V_out = 0.423311448760136 

179 L_in = log_decoding_VLog(V_out) 

180 

181 V_out = np.tile(V_out, 6) 

182 L_in = np.tile(L_in, 6) 

183 np.testing.assert_allclose( 

184 log_decoding_VLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS 

185 ) 

186 

187 V_out = np.reshape(V_out, (2, 3)) 

188 L_in = np.reshape(L_in, (2, 3)) 

189 np.testing.assert_allclose( 

190 log_decoding_VLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS 

191 ) 

192 

193 V_out = np.reshape(V_out, (2, 3, 1)) 

194 L_in = np.reshape(L_in, (2, 3, 1)) 

195 np.testing.assert_allclose( 

196 log_decoding_VLog(V_out), L_in, atol=TOLERANCE_ABSOLUTE_TESTS 

197 ) 

198 

199 def test_domain_range_scale_log_decoding_VLog(self) -> None: 

200 """ 

201 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

202log_decoding_VLog` definition domain and range scale support. 

203 """ 

204 

205 V_out = 0.423311448760136 

206 L_in = log_decoding_VLog(V_out) 

207 

208 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

209 for scale, factor in d_r: 

210 with domain_range_scale(scale): 

211 np.testing.assert_allclose( 

212 log_decoding_VLog(V_out * factor), 

213 L_in * factor, 

214 atol=TOLERANCE_ABSOLUTE_TESTS, 

215 ) 

216 

217 @ignore_numpy_errors 

218 def test_nan_log_decoding_VLog(self) -> None: 

219 """ 

220 Test :func:`colour.models.rgb.transfer_functions.panasonic_v_log.\ 

221log_decoding_VLog` definition nan support. 

222 """ 

223 

224 log_decoding_VLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))