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

21 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1""" 

2Recommendation ITU-R BT.601-7 

3============================= 

4 

5Define the *Recommendation ITU-R BT.601-7* opto-electrical transfer function 

6(OETF) and its inverse. 

7 

8- :func:`colour.models.oetf_BT601` 

9- :func:`colour.models.oetf_inverse_BT601` 

10 

11References 

12---------- 

13- :cite:`InternationalTelecommunicationUnion2011f` : International 

14 Telecommunication Union. (2011). Recommendation ITU-R BT.601-7 - Studio 

15 encoding parameters of digital television for standard 4:3 and wide-screen 

16 16:9 aspect ratios. 

17 http://www.itu.int/dms_pubrec/itu-r/rec/bt/\ 

18R-REC-BT.601-7-201103-I!!PDF-E.pdf 

19""" 

20 

21from __future__ import annotations 

22 

23import numpy as np 

24 

25from colour.algebra import spow 

26from colour.hints import ( # noqa: TC001 

27 Domain1, 

28 Range1, 

29) 

30from colour.utilities import as_float, domain_range_scale, from_range_1, to_domain_1 

31 

32__author__ = "Colour Developers" 

33__copyright__ = "Copyright 2013 Colour Developers" 

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

35__maintainer__ = "Colour Developers" 

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

37__status__ = "Production" 

38 

39__all__ = [ 

40 "oetf_BT601", 

41 "oetf_inverse_BT601", 

42] 

43 

44 

45def oetf_BT601(L: Domain1) -> Range1: 

46 """ 

47 Apply the *Recommendation ITU-R BT.601-7* opto-electronic transfer 

48 function (OETF). 

49 

50 Parameters 

51 ---------- 

52 L 

53 *Luminance* :math:`L` of the image. 

54 

55 Returns 

56 ------- 

57 :class:`numpy.ndarray` 

58 Electrical signal :math:`E`. 

59 

60 Notes 

61 ----- 

62 +------------+-----------------------+---------------+ 

63 | **Domain** | **Scale - Reference** | **Scale - 1** | 

64 +============+=======================+===============+ 

65 | ``L`` | 1 | 1 | 

66 +------------+-----------------------+---------------+ 

67 

68 +------------+-----------------------+---------------+ 

69 | **Range** | **Scale - Reference** | **Scale - 1** | 

70 +============+=======================+===============+ 

71 | ``E`` | 1 | 1 | 

72 +------------+-----------------------+---------------+ 

73 

74 References 

75 ---------- 

76 :cite:`InternationalTelecommunicationUnion2011f` 

77 

78 Examples 

79 -------- 

80 >>> oetf_BT601(0.18) # doctest: +ELLIPSIS 

81 0.4090077... 

82 """ 

83 

84 L = to_domain_1(L) 

85 

86 E = np.where(L < 0.018, L * 4.5, 1.099 * spow(L, 0.45) - 0.099) 

87 

88 return as_float(from_range_1(E)) 

89 

90 

91def oetf_inverse_BT601(E: Domain1) -> Range1: 

92 """ 

93 Apply the *Recommendation ITU-R BT.601-7* inverse opto-electronic 

94 transfer function (OETF). 

95 

96 Parameters 

97 ---------- 

98 E 

99 Electrical signal :math:`E`. 

100 

101 Returns 

102 ------- 

103 :class:`numpy.ndarray` 

104 *Luminance* :math:`L` of the image. 

105 

106 Notes 

107 ----- 

108 +------------+-----------------------+---------------+ 

109 | **Domain** | **Scale - Reference** | **Scale - 1** | 

110 +============+=======================+===============+ 

111 | ``E`` | 1 | 1 | 

112 +------------+-----------------------+---------------+ 

113 

114 +------------+-----------------------+---------------+ 

115 | **Range** | **Scale - Reference** | **Scale - 1** | 

116 +============+=======================+===============+ 

117 | ``L`` | 1 | 1 | 

118 +------------+-----------------------+---------------+ 

119 

120 References 

121 ---------- 

122 :cite:`InternationalTelecommunicationUnion2011f` 

123 

124 Examples 

125 -------- 

126 >>> oetf_inverse_BT601(0.409007728864150) # doctest: +ELLIPSIS 

127 0.1... 

128 """ 

129 

130 E = to_domain_1(E) 

131 

132 with domain_range_scale("ignore"): 

133 L = np.where( 

134 oetf_BT601(0.018) > E, 

135 E / 4.5, 

136 spow((E + 0.099) / 1.099, 1 / 0.45), 

137 ) 

138 

139 return as_float(from_range_1(L))