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

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\

3 xiaomi_mi_log` module.

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import (

10 log_decoding_MiLog,

11 log_encoding_MiLog,

12)

13 from colour.utilities import domain_range_scale, ignore_numpy_errors

14

15 __author__ = "Colour Developers"

16 __copyright__ = "Copyright 2013 Colour Developers"

17 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

18 __maintainer__ = "Colour Developers"

19 __email__ = "colour-developers@colour-science.org"

20 __status__ = "Production"

21

22 __all__ = [

23 "TestLogEncoding_MiLog",

24 "TestLogDecoding_MiLog",

25]

26

27

28 class TestLogEncoding_MiLog:

29 """

30 Define :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

31 log_encoding_MiLog` definition unit tests methods.

32 """

33

34 def test_log_encoding_MiLog(self) -> None:

35 """

36 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

37 log_encoding_MiLog` definition.

38 """

39

40 # Test values from the whitepaper

41 np.testing.assert_allclose(

42 log_encoding_MiLog(0.0),

43 0.14742742,

44 atol=TOLERANCE_ABSOLUTE_TESTS,

45 )

46

47 np.testing.assert_allclose(

48 log_encoding_MiLog(0.18),

49 0.45345968,

50 atol=TOLERANCE_ABSOLUTE_TESTS,

51 )

52

53 np.testing.assert_allclose(

54 log_encoding_MiLog(0.90),

55 0.66086763,

56 atol=TOLERANCE_ABSOLUTE_TESTS,

57 )

58

59 def test_n_dimensional_log_encoding_MiLog(self) -> None:

60 """

61 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

62 log_encoding_MiLog` definition n-dimensional arrays support.

63 """

64

65 R = 0.18

66 P = log_encoding_MiLog(R)

67

68 R = np.tile(R, 6)

69 P = np.tile(P, 6)

70 np.testing.assert_allclose(

71 log_encoding_MiLog(R), P, atol=TOLERANCE_ABSOLUTE_TESTS

72 )

73

74 R = np.reshape(R, (2, 3))

75 P = np.reshape(P, (2, 3))

76 np.testing.assert_allclose(

77 log_encoding_MiLog(R), P, atol=TOLERANCE_ABSOLUTE_TESTS

78 )

79

80 R = np.reshape(R, (2, 3, 1))

81 P = np.reshape(P, (2, 3, 1))

82 np.testing.assert_allclose(

83 log_encoding_MiLog(R), P, atol=TOLERANCE_ABSOLUTE_TESTS

84 )

85

86 def test_domain_range_scale_log_encoding_MiLog(self) -> None:

87 """

88 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

89 log_encoding_MiLog` definition domain and range scale support.

90 """

91

92 R = 0.18

93 P = log_encoding_MiLog(R)

94

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

96 for scale, factor in d_r:

97 with domain_range_scale(scale):

98 np.testing.assert_allclose(

99 log_encoding_MiLog(R * factor),

100 P * factor,

101 atol=TOLERANCE_ABSOLUTE_TESTS,

102 )

103

104 @ignore_numpy_errors

105 def test_nan_log_encoding_MiLog(self) -> None:

106 """

107 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

108 log_encoding_MiLog` definition nan support.

109 """

110

111 log_encoding_MiLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

112

113

114 class TestLogDecoding_MiLog:

115 """

116 Define :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

117 log_decoding_MiLog` definition unit tests methods.

118 """

119

120 def test_log_decoding_MiLog(self) -> None:

121 """

122 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

123 log_decoding_MiLog` definition.

124 """

125

126 # Test inverse of values from the whitepaper

127 np.testing.assert_allclose(

128 log_decoding_MiLog(0.14742742),

129 0.0,

130 atol=TOLERANCE_ABSOLUTE_TESTS,

131 )

132

133 np.testing.assert_allclose(

134 log_decoding_MiLog(0.45345968),

135 0.18,

136 atol=TOLERANCE_ABSOLUTE_TESTS,

137 )

138

139 np.testing.assert_allclose(

140 log_decoding_MiLog(0.66086763),

141 0.90,

142 atol=TOLERANCE_ABSOLUTE_TESTS,

143 )

144

145 def test_n_dimensional_log_decoding_MiLog(self) -> None:

146 """

147 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

148 log_decoding_MiLog` definition n-dimensional arrays support.

149 """

150

151 P = 0.45345968

152 R = log_decoding_MiLog(P)

153

154 P = np.tile(P, 6)

155 R = np.tile(R, 6)

156 np.testing.assert_allclose(

157 log_decoding_MiLog(P), R, atol=TOLERANCE_ABSOLUTE_TESTS

158 )

159

160 P = np.reshape(P, (2, 3))

161 R = np.reshape(R, (2, 3))

162 np.testing.assert_allclose(

163 log_decoding_MiLog(P), R, atol=TOLERANCE_ABSOLUTE_TESTS

164 )

165

166 P = np.reshape(P, (2, 3, 1))

167 R = np.reshape(R, (2, 3, 1))

168 np.testing.assert_allclose(

169 log_decoding_MiLog(P), R, atol=TOLERANCE_ABSOLUTE_TESTS

170 )

171

172 def test_domain_range_scale_log_decoding_MiLog(self) -> None:

173 """

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

175 log_decoding_MiLog` definition domain and range scale support.

176 """

177

178 P = 0.45345968

179 R = log_decoding_MiLog(P)

180

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

182 for scale, factor in d_r:

183 with domain_range_scale(scale):

184 np.testing.assert_allclose(

185 log_decoding_MiLog(P * factor),

186 R * factor,

187 atol=TOLERANCE_ABSOLUTE_TESTS,

188 )

189

190 @ignore_numpy_errors

191 def test_nan_log_decoding_MiLog(self) -> None:

192 """

193 Test :func:`colour.models.rgb.transfer_functions.xiaomi_mi_log.\

194 log_decoding_MiLog` definition nan support.

195 """

196

197 log_decoding_MiLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))