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
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""
2Recommendation ITU-R BT.601-7
3=============================
5Define the *Recommendation ITU-R BT.601-7* opto-electrical transfer function
6(OETF) and its inverse.
8- :func:`colour.models.oetf_BT601`
9- :func:`colour.models.oetf_inverse_BT601`
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"""
21from __future__ import annotations
23import numpy as np
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
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"
39__all__ = [
40 "oetf_BT601",
41 "oetf_inverse_BT601",
42]
45def oetf_BT601(L: Domain1) -> Range1:
46 """
47 Apply the *Recommendation ITU-R BT.601-7* opto-electronic transfer
48 function (OETF).
50 Parameters
51 ----------
52 L
53 *Luminance* :math:`L` of the image.
55 Returns
56 -------
57 :class:`numpy.ndarray`
58 Electrical signal :math:`E`.
60 Notes
61 -----
62 +------------+-----------------------+---------------+
63 | **Domain** | **Scale - Reference** | **Scale - 1** |
64 +============+=======================+===============+
65 | ``L`` | 1 | 1 |
66 +------------+-----------------------+---------------+
68 +------------+-----------------------+---------------+
69 | **Range** | **Scale - Reference** | **Scale - 1** |
70 +============+=======================+===============+
71 | ``E`` | 1 | 1 |
72 +------------+-----------------------+---------------+
74 References
75 ----------
76 :cite:`InternationalTelecommunicationUnion2011f`
78 Examples
79 --------
80 >>> oetf_BT601(0.18) # doctest: +ELLIPSIS
81 0.4090077...
82 """
84 L = to_domain_1(L)
86 E = np.where(L < 0.018, L * 4.5, 1.099 * spow(L, 0.45) - 0.099)
88 return as_float(from_range_1(E))
91def oetf_inverse_BT601(E: Domain1) -> Range1:
92 """
93 Apply the *Recommendation ITU-R BT.601-7* inverse opto-electronic
94 transfer function (OETF).
96 Parameters
97 ----------
98 E
99 Electrical signal :math:`E`.
101 Returns
102 -------
103 :class:`numpy.ndarray`
104 *Luminance* :math:`L` of the image.
106 Notes
107 -----
108 +------------+-----------------------+---------------+
109 | **Domain** | **Scale - Reference** | **Scale - 1** |
110 +============+=======================+===============+
111 | ``E`` | 1 | 1 |
112 +------------+-----------------------+---------------+
114 +------------+-----------------------+---------------+
115 | **Range** | **Scale - Reference** | **Scale - 1** |
116 +============+=======================+===============+
117 | ``L`` | 1 | 1 |
118 +------------+-----------------------+---------------+
120 References
121 ----------
122 :cite:`InternationalTelecommunicationUnion2011f`
124 Examples
125 --------
126 >>> oetf_inverse_BT601(0.409007728864150) # doctest: +ELLIPSIS
127 0.1...
128 """
130 E = to_domain_1(E)
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 )
139 return as_float(from_range_1(L))