/
aces.py
423 lines (341 loc) · 12.9 KB
/
aces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# -*- coding: utf-8 -*-
"""
Academy Color Encoding System - Log Encodings
=============================================
Defines the *Academy Color Encoding System* (ACES) log encodings:
- :func:`colour.models.log_encoding_ACESproxy`
- :func:`colour.models.log_decoding_ACESproxy`
- :func:`colour.models.log_encoding_ACEScc`
- :func:`colour.models.log_decoding_ACEScc`
- :func:'log_encoding_ACEScct'
- :func:'log_decoding_ACEScct'
See Also
--------
`RGB Colourspaces Jupyter Notebook
<http://nbviewer.jupyter.org/github/colour-science/colour-notebooks/\
blob/master/notebooks/models/rgb.ipynb>`_
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q` : The Academy of
Motion Picture Arts and Sciences, Science and Technology Council, & Academy
Color Encoding System (ACES) Project Subcommittee. (2014). Technical
Bulletin TB-2014-004 - Informative Notes on SMPTE ST 2065-1 - Academy Color
Encoding Specification (ACES). Retrieved from
https://github.com/ampas/aces-dev/tree/master/documents
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r` : The Academy of
Motion Picture Arts and Sciences, Science and Technology Council, & Academy
Color Encoding System (ACES) Project Subcommittee. (2014). Technical
Bulletin TB-2014-012 - Academy Color Encoding System Version 1.0 Component
Names. Retrieved from
https://github.com/ampas/aces-dev/tree/master/documents
- :cite:`TheAcademyofMotionPictureArtsandSciences2014s` : The Academy of
Motion Picture Arts and Sciences, Science and Technology Council, & Academy
Color Encoding System (ACES) Project Subcommittee. (2014). Specification
S-2013-001 - ACESproxy , an Integer Log Encoding of ACES Image Data.
Retrieved from https://github.com/ampas/aces-dev/tree/master/documents
- :cite:`TheAcademyofMotionPictureArtsandSciences2014t` : The Academy of
Motion Picture Arts and Sciences, Science and Technology Council, & Academy
Color Encoding System (ACES) Project Subcommittee. (2014). Specification
S-2014-003 - ACEScc , A Logarithmic Encoding of ACES Data for use within
Color Grading Systems. Retrieved from
https://github.com/ampas/aces-dev/tree/master/documents
- :cite:`TheAcademyofMotionPictureArtsandSciences2016c` : The Academy of
Motion Picture Arts and Sciences, Science and Technology Council, & Academy
Color Encoding System (ACES) Project. (2016). Specification S-2016-001 -
ACEScct, A Quasi-Logarithmic Encoding of ACES Data for use within Color
Grading Systems. Retrieved October 10, 2016, from
https://github.com/ampas/aces-dev/tree/v1.0.3/documents
- :cite:`TheAcademyofMotionPictureArtsandSciencese` : The Academy of Motion
Picture Arts and Sciences, Science and Technology Council, & Academy Color
Encoding System (ACES) Project Subcommittee. (n.d.). Academy Color Encoding
System. Retrieved February 24, 2014, from
http://www.oscars.org/science-technology/council/projects/aces.html
"""
from __future__ import division, unicode_literals
import numpy as np
from colour.utilities import Structure, as_numeric
__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2018 - Colour Developers'
__license__ = 'New BSD License - http://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'
__all__ = [
'ACES_PROXY_10_CONSTANTS', 'ACES_PROXY_12_CONSTANTS',
'ACES_PROXY_CONSTANTS', 'ACES_CCT_CONSTANTS', 'log_encoding_ACESproxy',
'log_decoding_ACESproxy', 'log_encoding_ACEScc', 'log_decoding_ACEScc',
'log_encoding_ACEScct', 'log_decoding_ACEScct'
]
ACES_PROXY_10_CONSTANTS = Structure(
CV_min=64,
CV_max=940,
steps_per_stop=50,
mid_CV_offset=425,
mid_log_offset=2.5)
"""
*ACESproxy* 10 bit colourspace constants.
ACES_PROXY_10_CONSTANTS : Structure
"""
ACES_PROXY_12_CONSTANTS = Structure(
CV_min=256,
CV_max=3760,
steps_per_stop=200,
mid_CV_offset=1700,
mid_log_offset=2.5)
"""
*ACESproxy* 12 bit colourspace constants.
ACES_PROXY_12_CONSTANTS : Structure
"""
ACES_PROXY_CONSTANTS = {
10: ACES_PROXY_10_CONSTANTS,
12: ACES_PROXY_12_CONSTANTS
}
"""
Aggregated *ACESproxy* colourspace constants.
ACES_PROXY_CONSTANTS : dict
**{10, 12}**
"""
ACES_CCT_CONSTANTS = Structure(
X_BRK=0.0078125,
Y_BRK=0.155251141552511,
A=10.5402377416545,
B=0.0729055341958355)
"""
*ACEScct* colourspace constants.
ACES_CCT_CONSTANTS : Structure
"""
def log_encoding_ACESproxy(lin_AP1, bit_depth=10):
"""
Defines the *ACESproxy* colourspace log encoding curve / opto-electronic
transfer function.
Parameters
----------
lin_AP1 : numeric or array_like
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
*lin_AP1* value.
bit_depth : int, optional
**{10, 12}**,
*ACESproxy* bit depth.
Returns
-------
numeric or ndarray
metadata : {'type': 'ACESproxy', 'symbol': 'ACES\_\{proxy\}',
'extent': (64, 940)}
:math:`ACES_{proxy}` non-linear value.
Notes
-----
- metadata : {'classifier': 'Log Encoding Curve', 'method_name':
'ACESproxy', 'method_strict_name': 'ACES\_\{proxy\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014s`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_encoding_ACESproxy(0.18)
426
"""
lin_AP1 = np.asarray(lin_AP1)
constants = ACES_PROXY_CONSTANTS[bit_depth]
CV_min = np.resize(constants.CV_min, lin_AP1.shape)
CV_max = np.resize(constants.CV_max, lin_AP1.shape)
def float_2_cv(x):
"""
Converts given numeric to code value.
"""
return np.maximum(CV_min, np.minimum(CV_max, np.round(x)))
output = np.where(
lin_AP1 > 2 ** -9.72,
float_2_cv((np.log2(lin_AP1) + constants.mid_log_offset) *
constants.steps_per_stop + constants.mid_CV_offset),
np.resize(CV_min, lin_AP1.shape))
return as_numeric(output, int)
def log_decoding_ACESproxy(ACESproxy, bit_depth=10):
"""
Defines the *ACESproxy* colourspace log decoding curve / electro-optical
transfer function.
Parameters
----------
ACESproxy : numeric or array_like
metadata : {'type': 'ACESproxy', 'symbol': 'ACES\_\{proxy\}',
'extent': (64, 940)}
*ACESproxy* non-linear value.
bit_depth : int, optional
**{10, 12}**,
*ACESproxy* bit depth.
Returns
-------
numeric or ndarray
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
:math:`lin_{AP1}` value.
Notes
-----
- metadata : {'classifier': 'Log Decoding Curve', 'method_name':
'ACESproxy', 'method_strict_name': 'ACES\_\{proxy\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014s`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_decoding_ACESproxy(426) # doctest: +ELLIPSIS
0.1792444...
"""
ACESproxy = np.asarray(ACESproxy).astype(np.int)
constants = ACES_PROXY_CONSTANTS[bit_depth]
return (2 **
(((ACESproxy - constants.mid_CV_offset) / constants.steps_per_stop
- constants.mid_log_offset)))
def log_encoding_ACEScc(lin_AP1):
"""
Defines the *ACEScc* colourspace log encoding / opto-electronic transfer
function.
Parameters
----------
lin_AP1 : numeric or array_like
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
:math:`lin_{AP1}` value.
Returns
-------
numeric or ndarray
metadata : {'type': 'ACEScc', 'symbol': 'ACES\_\{cc\}',
'extent': (-0.358447488584475, 1.467996312044715)}
:math:`ACES_{cc}` non-linear value.
Notes
-----
- metadata : {'classifier': 'Log Encoding Curve', 'method_name':
'ACEScc', 'method_strict_name': 'ACES\_\{cc\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014t`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_encoding_ACEScc(0.18) # doctest: +ELLIPSIS
0.4135884...
"""
lin_AP1 = np.asarray(lin_AP1)
output = np.where(lin_AP1 < 0, (np.log2(2 ** -16) + 9.72) / 17.52,
(np.log2(2 ** -16 + lin_AP1 * 0.5) + 9.72) / 17.52)
output = np.where(lin_AP1 >= 2 ** -15, (np.log2(lin_AP1) + 9.72) / 17.52,
output)
return as_numeric(output)
def log_decoding_ACEScc(ACEScc):
"""
Defines the *ACEScc* colourspace log decoding / electro-optical transfer
function.
Parameters
----------
ACEScc : numeric or array_like
metadata : {'type': 'ACEScc', 'symbol': 'ACES\_\{cc\}',
'extent': (-0.358447488584475, 1.467996312044715)}
:math:`ACES_{cc}` non-linear value.
Returns
-------
numeric or ndarray
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
:math:`lin_{AP1}` value.
Notes
-----
- metadata : {'classifier': 'Log Decoding Curve', 'method_name':
'ACEScc', 'method_strict_name': 'ACES\_\{cc\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014t`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_decoding_ACEScc(0.413588402492442) # doctest: +ELLIPSIS
0.1799999...
"""
ACEScc = np.asarray(ACEScc)
output = np.where(ACEScc < (9.72 - 15) / 17.52,
(2 ** (ACEScc * 17.52 - 9.72) - 2 ** -16) * 2, 2
** (ACEScc * 17.52 - 9.72))
output = np.where(ACEScc >= (np.log2(65504) + 9.72) / 17.52, 65504, output)
return as_numeric(output)
def log_encoding_ACEScct(lin_AP1):
"""
Defines the *ACEScct* colourspace log encoding / opto-electronic transfer
function.
Parameters
----------
lin_AP1 : numeric or array_like
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
:math:`lin_AP1` value.
Returns
-------
numeric or ndarray
metadata : {'type': 'ACEScct', 'symbol': 'ACES\_\{cct\}',
'extent': (-690427.660123802255839, 1.467996312044715)}
:math:`ACES_{cct}` non-linear value.
Notes
-----
- metadata : {'classifier': 'Log Encoding Curve', 'method_name':
'ACEScct', 'method_strict_name': 'ACES\_\{cct\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2016c`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_encoding_ACEScct(0.18) # doctest: +ELLIPSIS
0.4135884...
"""
constants = ACES_CCT_CONSTANTS
lin_AP1 = np.asarray(lin_AP1)
output = np.where(lin_AP1 <= constants.X_BRK,
constants.A * lin_AP1 + constants.B,
(np.log2(lin_AP1) + 9.72) / 17.52)
return as_numeric(output)
def log_decoding_ACEScct(ACEScct):
"""
Defines the *ACEScct* colourspace log decoding / electro-optical transfer
function.
Parameters
----------
ACEScct : numeric or array_like
metadata : {'type': 'ACEScct', 'symbol': 'ACES\_\{cct\}',
'extent': (-690427.660123802255839, 1.467996312044715)}
:math:`ACES_{cct}` non-linear value.
Returns
-------
numeric or ndarray
metadata : {'type': 'lin AP1', 'symbol': 'lin\_\{AP1\}',
'extent': (-65504, 65504)}
:math:`lin_AP1` value.
Notes
-----
- metadata : {'classifier': 'Log Decoding Curve', 'method_name':
'ACEScct', 'method_strict_name': 'ACES\_\{cct\}'}
References
----------
- :cite:`TheAcademyofMotionPictureArtsandSciences2014q`
- :cite:`TheAcademyofMotionPictureArtsandSciences2014r`
- :cite:`TheAcademyofMotionPictureArtsandSciences2016c`
- :cite:`TheAcademyofMotionPictureArtsandSciencese`
Examples
--------
>>> log_decoding_ACEScct(0.413588402492442) # doctest: +ELLIPSIS
0.1799999...
"""
constants = ACES_CCT_CONSTANTS
ACEScct = np.asarray(ACEScct)
output = np.where(ACEScct > constants.Y_BRK, 2 ** (ACEScct * 17.52 - 9.72),
(ACEScct - constants.B) / constants.A)
return as_numeric(output)