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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.itur_bt_709` 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 oetf_BT709, oetf_inverse_BT709

10 from 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

25 class 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.\

34 oetf_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.\

52 oetf_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.\

73 oetf_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.\

92 oetf_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

98 class TestOetf_inverse_BT709:

99 """

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

101 oetf_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.\

107 oetf_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.\

133 oetf_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.\

160 oetf_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.\

179 oetf_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]))