Coverage for models/rgb/transfer_functions/st_2084.py: 60%
40 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2SMPTE ST 2084:2014
3==================
5Define the *SMPTE ST 2084:2014* electro-optical transfer function (EOTF) and
6its inverse.
8- :func:`colour.models.eotf_inverse_ST2084`
9- :func:`colour.models.eotf_ST2084`
11References
12----------
13- :cite:`Miller2014a` : Miller, S. (2014). A Perceptual EOTF for Extended
14 Dynamic Range Imagery (pp. 1-17).
15 https://www.smpte.org/sites/default/files/\
162014-05-06-EOTF-Miller-1-2-handout.pdf
17- :cite:`SocietyofMotionPictureandTelevisionEngineers2014a` : Society of
18 Motion Picture and Television Engineers. (2014). SMPTE ST 2084:2014 -
19 Dynamic Range Electro-Optical Transfer Function of Mastering Reference
20 Displays (pp. 1-14). doi:10.5594/SMPTE.ST2084.2014
21"""
23from __future__ import annotations
25import typing
27import numpy as np
29from colour.algebra import spow
31if typing.TYPE_CHECKING:
32 from colour.hints import ArrayLike, NDArrayFloat
34from colour.utilities import Structure, as_float, as_float_array, optional
36__author__ = "Colour Developers"
37__copyright__ = "Copyright 2013 Colour Developers"
38__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
39__maintainer__ = "Colour Developers"
40__email__ = "colour-developers@colour-science.org"
41__status__ = "Production"
43__all__ = [
44 "CONSTANTS_ST2084",
45 "eotf_inverse_ST2084",
46 "eotf_ST2084",
47]
49CONSTANTS_ST2084: Structure = Structure(
50 m_1=2610 / 4096 * (1 / 4),
51 m_2=2523 / 4096 * 128,
52 c_1=3424 / 4096,
53 c_2=2413 / 4096 * 32,
54 c_3=2392 / 4096 * 32,
55)
56"""
57Constants for *SMPTE ST 2084:2014* inverse electro-optical transfer function
58(EOTF) and electro-optical transfer function (EOTF).
59"""
62def eotf_inverse_ST2084(
63 C: ArrayLike,
64 L_p: float = 10000,
65 constants: Structure | None = None,
66) -> NDArrayFloat:
67 """
68 Apply the *SMPTE ST 2084:2014* perceptual quantizer (PQ) inverse
69 electro-optical transfer function (EOTF).
71 Parameters
72 ----------
73 C
74 Target optical output :math:`C` in :math:`cd/m^2` of the ideal
75 reference display.
76 L_p
77 System peak luminance in :math:`cd/m^2`. This parameter should remain
78 at its default value of :math:`10000 cd/m^2` for practical
79 applications. It is exposed to enable the definition's use as a
80 fitting function.
81 constants
82 *SMPTE ST 2084:2014* constants.
84 Returns
85 -------
86 :class:`numpy.ndarray`
87 Colour value abbreviated as :math:`N`, directly proportional to the
88 encoded signal representation and not directly proportional to the
89 optical output of a display device.
91 Warnings
92 --------
93 *SMPTE ST 2084:2014* is an absolute transfer function.
95 Notes
96 -----
97 - *SMPTE ST 2084:2014* is an absolute transfer function; thus, the
98 domain and range values for the *Reference* and *1* scales are only
99 indicative that the data is not affected by scale transformations.
100 The effective domain of the *SMPTE ST 2084:2014* inverse
101 electro-optical transfer function (EOTF) is [0.0001, 10000].
103 +------------+-----------------------+---------------+
104 | **Domain** | **Scale - Reference** | **Scale - 1** |
105 +============+=======================+===============+
106 | ``C`` | ``UN`` | ``UN`` |
107 +------------+-----------------------+---------------+
109 +------------+-----------------------+---------------+
110 | **Range** | **Scale - Reference** | **Scale - 1** |
111 +============+=======================+===============+
112 | ``N`` | ``UN`` | ``UN`` |
113 +------------+-----------------------+---------------+
115 References
116 ----------
117 :cite:`Miller2014a`,
118 :cite:`SocietyofMotionPictureandTelevisionEngineers2014a`
120 Examples
121 --------
122 >>> eotf_inverse_ST2084(100) # doctest: +ELLIPSIS
123 0.5080784...
124 """
126 C = as_float_array(C)
127 constants = optional(constants, CONSTANTS_ST2084)
129 c_1 = constants.c_1
130 c_2 = constants.c_2
131 c_3 = constants.c_3
132 m_1 = constants.m_1
133 m_2 = constants.m_2
135 Y_p = spow(C / L_p, m_1)
137 N = spow((c_1 + c_2 * Y_p) / (c_3 * Y_p + 1), m_2)
139 return as_float(N)
142def eotf_ST2084(
143 N: ArrayLike,
144 L_p: float = 10000,
145 constants: Structure | None = None,
146) -> NDArrayFloat:
147 """
148 Apply the *SMPTE ST 2084:2014* perceptual quantizer (PQ) electro-optical
149 transfer function (EOTF).
151 Parameters
152 ----------
153 N
154 Colour value abbreviated as :math:`N`, directly proportional to the
155 encoded signal representation and not directly proportional to the
156 optical output of a display device.
157 L_p
158 System peak luminance in :math:`cd/m^2`. This parameter should remain
159 at its default value of :math:`10000 cd/m^2` for practical
160 applications. It is exposed to enable the definition's use as a
161 fitting function.
162 constants
163 *SMPTE ST 2084:2014* constants.
165 Returns
166 -------
167 :class:`numpy.ndarray`
168 Target optical output :math:`C` in :math:`cd/m^2` of the ideal
169 reference display.
171 Warnings
172 --------
173 *SMPTE ST 2084:2014* is an absolute transfer function.
175 Notes
176 -----
177 - *SMPTE ST 2084:2014* is an absolute transfer function, thus the
178 domain and range values for the *Reference* and *1* scales are only
179 indicative that the data is not affected by scale transformations.
181 +------------+-----------------------+---------------+
182 | **Domain** | **Scale - Reference** | **Scale - 1** |
183 +============+=======================+===============+
184 | ``N`` | ``UN`` | ``UN`` |
185 +------------+-----------------------+---------------+
187 +------------+-----------------------+---------------+
188 | **Range** | **Scale - Reference** | **Scale - 1** |
189 +============+=======================+===============+
190 | ``C`` | ``UN`` | ``UN`` |
191 +------------+-----------------------+---------------+
193 References
194 ----------
195 :cite:`Miller2014a`,
196 :cite:`SocietyofMotionPictureandTelevisionEngineers2014a`
198 Examples
199 --------
200 >>> eotf_ST2084(0.508078421517399) # doctest: +ELLIPSIS
201 100.0000000...
202 """
204 N = as_float_array(N)
205 constants = optional(constants, CONSTANTS_ST2084)
207 c_1 = constants.c_1
208 c_2 = constants.c_2
209 c_3 = constants.c_3
210 m_1 = constants.m_1
211 m_2 = constants.m_2
213 m_1_d = 1 / m_1
214 m_2_d = 1 / m_2
216 V_p = spow(N, m_2_d)
217 n = np.maximum(0, V_p - c_1)
218 L = spow((n / (c_2 - c_3 * V_p)), m_1_d)
219 C = L_p * L
221 return as_float(C)