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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.dicom_gsdf` 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 eotf_DICOMGSDF, eotf_inverse_DICOMGSDF

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

21 "TestEotf_DICOMGSDF",

22]

23

24

25 class TestEotf_inverse_DICOMGSDF:

26 """

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

28 eotf_inverse_DICOMGSDF` definition unit tests methods.

29 """

30

31 def test_eotf_inverse_DICOMGSDF(self) -> None:

32 """

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

34 eotf_inverse_DICOMGSDF` definition.

35 """

36

37 np.testing.assert_allclose(

38 eotf_inverse_DICOMGSDF(0.05),

39 0.001007281350787,

40 atol=TOLERANCE_ABSOLUTE_TESTS,

41 )

42

43 np.testing.assert_allclose(

44 eotf_inverse_DICOMGSDF(130.0662),

45 0.500486263438448,

46 atol=TOLERANCE_ABSOLUTE_TESTS,

47 )

48

49 np.testing.assert_allclose(

50 eotf_inverse_DICOMGSDF(4000),

51 1.000160314715578,

52 atol=TOLERANCE_ABSOLUTE_TESTS,

53 )

54

55 np.testing.assert_allclose(

56 eotf_inverse_DICOMGSDF(130.0662, out_int=True),

57 512,

58 atol=TOLERANCE_ABSOLUTE_TESTS,

59 )

60

61 def test_n_dimensional_eotf_inverse_DICOMGSDF(self) -> None:

62 """

63 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

64 eotf_inverse_DICOMGSDF` definition n-dimensional arrays support.

65 """

66

67 L = 130.0662

68 J = eotf_inverse_DICOMGSDF(L)

69

70 L = np.tile(L, 6)

71 J = np.tile(J, 6)

72 np.testing.assert_allclose(

73 eotf_inverse_DICOMGSDF(L), J, atol=TOLERANCE_ABSOLUTE_TESTS

74 )

75

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

77 J = np.reshape(J, (2, 3))

78 np.testing.assert_allclose(

79 eotf_inverse_DICOMGSDF(L), J, atol=TOLERANCE_ABSOLUTE_TESTS

80 )

81

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

83 J = np.reshape(J, (2, 3, 1))

84 np.testing.assert_allclose(

85 eotf_inverse_DICOMGSDF(L), J, atol=TOLERANCE_ABSOLUTE_TESTS

86 )

87

88 def test_domain_range_scale_eotf_inverse_DICOMGSDF(self) -> None:

89 """

90 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

91 eotf_inverse_DICOMGSDF` definition domain and range scale support.

92 """

93

94 L = 130.0662

95 J = eotf_inverse_DICOMGSDF(L)

96

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

98 for scale, factor in d_r:

99 with domain_range_scale(scale):

100 np.testing.assert_allclose(

101 eotf_inverse_DICOMGSDF(L * factor),

102 J * factor,

103 atol=TOLERANCE_ABSOLUTE_TESTS,

104 )

105

106 @ignore_numpy_errors

107 def test_nan_eotf_inverse_DICOMGSDF(self) -> None:

108 """

109 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

110 eotf_inverse_DICOMGSDF` definition nan support.

111 """

112

113 eotf_inverse_DICOMGSDF(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

114

115

116 class TestEotf_DICOMGSDF:

117 """

118 Define :func:`colour.models.rgb.transfer_functions.dicom_gsdf.

119 eotf_DICOMGSDF` definition unit tests methods.

120 """

121

122 def test_eotf_DICOMGSDF(self) -> None:

123 """

124 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

125 eotf_DICOMGSDF` definition.

126 """

127

128 np.testing.assert_allclose(

129 eotf_DICOMGSDF(0.001007281350787),

130 0.050143440671692,

131 atol=TOLERANCE_ABSOLUTE_TESTS,

132 )

133

134 np.testing.assert_allclose(

135 eotf_DICOMGSDF(0.500486263438448),

136 130.062864706476550,

137 atol=TOLERANCE_ABSOLUTE_TESTS,

138 )

139

140 np.testing.assert_allclose(

141 eotf_DICOMGSDF(1.000160314715578),

142 3997.586161113322300,

143 atol=TOLERANCE_ABSOLUTE_TESTS,

144 )

145

146 np.testing.assert_allclose(

147 eotf_DICOMGSDF(512, in_int=True),

148 130.065284012159790,

149 atol=TOLERANCE_ABSOLUTE_TESTS,

150 )

151

152 def test_n_dimensional_eotf_DICOMGSDF(self) -> None:

153 """

154 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

155 eotf_DICOMGSDF` definition n-dimensional arrays support.

156 """

157

158 J = 0.500486263438448

159 L = eotf_DICOMGSDF(J)

160

161 J = np.tile(J, 6)

162 L = np.tile(L, 6)

163 np.testing.assert_allclose(eotf_DICOMGSDF(J), L, atol=TOLERANCE_ABSOLUTE_TESTS)

164

165 J = np.reshape(J, (2, 3))

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

167 np.testing.assert_allclose(eotf_DICOMGSDF(J), L, atol=TOLERANCE_ABSOLUTE_TESTS)

168

169 J = np.reshape(J, (2, 3, 1))

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

171 np.testing.assert_allclose(eotf_DICOMGSDF(J), L, atol=TOLERANCE_ABSOLUTE_TESTS)

172

173 def test_domain_range_scale_eotf_DICOMGSDF(self) -> None:

174 """

175 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

176 eotf_DICOMGSDF` definition domain and range scale support.

177 """

178

179 J = 0.500486263438448

180 L = eotf_DICOMGSDF(J)

181

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

183 for scale, factor in d_r:

184 with domain_range_scale(scale):

185 np.testing.assert_allclose(

186 eotf_DICOMGSDF(J * factor),

187 L * factor,

188 atol=TOLERANCE_ABSOLUTE_TESTS,

189 )

190

191 @ignore_numpy_errors

192 def test_nan_eotf_DICOMGSDF(self) -> None:

193 """

194 Test :func:`colour.models.rgb.transfer_functions.dicom_gsdf.\

195 eotf_DICOMGSDF` definition nan support.

196 """

197

198 eotf_DICOMGSDF(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))