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

67 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1""" 

2Define the unit tests for the 

3:mod:`colour.models.rgb.transfer_functions.itur_bt_709` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import oetf_BT709, oetf_inverse_BT709 

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 "TestOetf_BT709", 

21 "TestOetf_inverse_BT709", 

22] 

23 

24 

25class TestOetf_BT709: 

26 """ 

27 Define :func:`colour.models.rgb.transfer_functions.itur_bt_709.oetf_BT709` 

28 definition unit tests methods. 

29 """ 

30 

31 def test_oetf_BT709(self) -> None: 

32 """ 

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

34oetf_BT709` definition. 

35 """ 

36 

37 np.testing.assert_allclose(oetf_BT709(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS) 

38 

39 np.testing.assert_allclose( 

40 oetf_BT709(0.015), 0.067500000000000, atol=TOLERANCE_ABSOLUTE_TESTS 

41 ) 

42 

43 np.testing.assert_allclose( 

44 oetf_BT709(0.18), 0.409007728864150, atol=TOLERANCE_ABSOLUTE_TESTS 

45 ) 

46 

47 np.testing.assert_allclose(oetf_BT709(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS) 

48 

49 def test_n_dimensional_oetf_BT709(self) -> None: 

50 """ 

51 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

52oetf_BT709` definition n-dimensional arrays support. 

53 """ 

54 

55 L = 0.18 

56 V = oetf_BT709(L) 

57 

58 L = np.tile(L, 6) 

59 V = np.tile(V, 6) 

60 np.testing.assert_allclose(oetf_BT709(L), V, atol=TOLERANCE_ABSOLUTE_TESTS) 

61 

62 L = np.reshape(L, (2, 3)) 

63 V = np.reshape(V, (2, 3)) 

64 np.testing.assert_allclose(oetf_BT709(L), V, atol=TOLERANCE_ABSOLUTE_TESTS) 

65 

66 L = np.reshape(L, (2, 3, 1)) 

67 V = np.reshape(V, (2, 3, 1)) 

68 np.testing.assert_allclose(oetf_BT709(L), V, atol=TOLERANCE_ABSOLUTE_TESTS) 

69 

70 def test_domain_range_scale_oetf_BT709(self) -> None: 

71 """ 

72 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

73oetf_BT709` definition domain and range scale support. 

74 """ 

75 

76 L = 0.18 

77 V = oetf_BT709(L) 

78 

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 oetf_BT709(L * factor), 

84 V * factor, 

85 atol=TOLERANCE_ABSOLUTE_TESTS, 

86 ) 

87 

88 @ignore_numpy_errors 

89 def test_nan_oetf_BT709(self) -> None: 

90 """ 

91 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

92oetf_BT709` definition nan support. 

93 """ 

94 

95 oetf_BT709(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

96 

97 

98class TestOetf_inverse_BT709: 

99 """ 

100 Define :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

101oetf_inverse_BT709` definition unit tests methods. 

102 """ 

103 

104 def test_oetf_inverse_BT709(self) -> None: 

105 """ 

106 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

107oetf_inverse_BT709` definition. 

108 """ 

109 

110 np.testing.assert_allclose( 

111 oetf_inverse_BT709(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

112 ) 

113 

114 np.testing.assert_allclose( 

115 oetf_inverse_BT709(0.067500000000000), 

116 0.015, 

117 atol=TOLERANCE_ABSOLUTE_TESTS, 

118 ) 

119 

120 np.testing.assert_allclose( 

121 oetf_inverse_BT709(0.409007728864150), 

122 0.18, 

123 atol=TOLERANCE_ABSOLUTE_TESTS, 

124 ) 

125 

126 np.testing.assert_allclose( 

127 oetf_inverse_BT709(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS 

128 ) 

129 

130 def test_n_dimensional_oetf_inverse_BT709(self) -> None: 

131 """ 

132 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

133oetf_inverse_BT709` definition n-dimensional arrays support. 

134 """ 

135 

136 V = 0.409007728864150 

137 L = oetf_inverse_BT709(V) 

138 

139 V = np.tile(V, 6) 

140 L = np.tile(L, 6) 

141 np.testing.assert_allclose( 

142 oetf_inverse_BT709(V), L, atol=TOLERANCE_ABSOLUTE_TESTS 

143 ) 

144 

145 V = np.reshape(V, (2, 3)) 

146 L = np.reshape(L, (2, 3)) 

147 np.testing.assert_allclose( 

148 oetf_inverse_BT709(V), L, atol=TOLERANCE_ABSOLUTE_TESTS 

149 ) 

150 

151 V = np.reshape(V, (2, 3, 1)) 

152 L = np.reshape(L, (2, 3, 1)) 

153 np.testing.assert_allclose( 

154 oetf_inverse_BT709(V), L, atol=TOLERANCE_ABSOLUTE_TESTS 

155 ) 

156 

157 def test_domain_range_scale_oetf_inverse_BT709(self) -> None: 

158 """ 

159 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

160oetf_inverse_BT709` definition domain and range scale support. 

161 """ 

162 

163 V = 0.409007728864150 

164 L = oetf_inverse_BT709(V) 

165 

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

167 for scale, factor in d_r: 

168 with domain_range_scale(scale): 

169 np.testing.assert_allclose( 

170 oetf_inverse_BT709(V * factor), 

171 L * factor, 

172 atol=TOLERANCE_ABSOLUTE_TESTS, 

173 ) 

174 

175 @ignore_numpy_errors 

176 def test_nan_oetf_inverse_BT709(self) -> None: 

177 """ 

178 Test :func:`colour.models.rgb.transfer_functions.itur_bt_709.\ 

179oetf_inverse_BT709` definition nan support. 

180 """ 

181 

182 oetf_inverse_BT709(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))