Skip to content

Instantly share code, notes, and snippets.

@remia
Created June 28, 2021 11:47
Show Gist options
  • Save remia/380d972fa568493d570f2ba298b3f23a to your computer and use it in GitHub Desktop.
Save remia/380d972fa568493d570f2ba298b3f23a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import sys
import colour
import numpy as np
import subprocess
def cc_24_acescg():
# ColorChecker 24 values as per SMPTE 2065-1
CC24 = np.array([
[0.11877, 0.08709, 0.05895],
[0.40002, 0.31916, 0.23736],
[0.18476, 0.20398, 0.31311],
[0.10901, 0.13511, 0.06493],
[0.26684, 0.24604, 0.40932],
[0.32283, 0.46208, 0.40606],
[0.38605, 0.22743, 0.05777],
[0.13822, 0.13037, 0.33703],
[0.30202, 0.13752, 0.12758],
[0.09310, 0.06347, 0.13525],
[0.34876, 0.43654, 0.10613],
[0.48655, 0.36685, 0.08061],
[0.08732, 0.07443, 0.27274],
[0.15366, 0.25692, 0.09071],
[0.21742, 0.07070, 0.05130],
[0.58919, 0.53943, 0.09157],
[0.30904, 0.14818, 0.27426],
[0.14901, 0.23378, 0.35939]
])
CC24_AP1 = colour.RGB_to_RGB(
CC24,
colour.models.RGB_COLOURSPACE_ACES2065_1,
colour.models.RGB_COLOURSPACE_ACESCG
)
return CC24_AP1
def bmd_wide_gamut():
BMD_WIDE_GAMUT_PRIMARIES = np.array([
[0.7177215, 0.3171181],
[0.2280410, 0.8615690],
[0.1005841, -0.0820452]
])
BMD_WIDE_GAMUT_WHITEPOINT_NAME = 'D65'
BMD_WIDE_GAMUT_WHITEPOINT = [0.3127170, 0.3290312]
BMD_WIDE_GAMUT_TO_XYZ_MATRIX = np.array([
[ 0.606530, 0.220408, 0.123479],
[ 0.267989, 0.832731, -0.100720],
[-0.029442, -0.086611, 1.204861]
])
XYZ_TO_BMD_WIDE_GAMUT_MATRIX = np.array([
[ 1.866382, -0.518397, -0.234610],
[-0.600342, 1.378149, 0.176732],
[ 0.002452, 0.086400, 0.836943]
])
return colour.RGB_Colourspace(
'BMD Wide Gamut',
BMD_WIDE_GAMUT_PRIMARIES,
BMD_WIDE_GAMUT_WHITEPOINT,
BMD_WIDE_GAMUT_WHITEPOINT_NAME,
BMD_WIDE_GAMUT_TO_XYZ_MATRIX,
XYZ_TO_BMD_WIDE_GAMUT_MATRIX,
)
def generate_test_dataset():
RGB_COLOURSPACE_BMD_WIDE_GAMUT = bmd_wide_gamut()
spaces = [
[colour.models.RGB_COLOURSPACE_ALEXA_WIDE_GAMUT, 'CAT02'],
[RGB_COLOURSPACE_BMD_WIDE_GAMUT, 'Bradford'],
[colour.models.RGB_COLOURSPACE_CINEMA_GAMUT, 'CAT02'],
[colour.models.RGB_COLOURSPACE_RED_WIDE_GAMUT_RGB, 'Bradford'],
[colour.models.RGB_COLOURSPACE_S_GAMUT3, 'CAT02'],
[colour.models.RGB_COLOURSPACE_VENICE_S_GAMUT3, 'CAT02'],
[colour.models.RGB_COLOURSPACE_V_GAMUT, 'CAT02']
]
limit = np.array([
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]
])
camera_rgb = np.vstack([
colour.models.RGB_to_RGB(
limit,
space,
colour.models.RGB_COLOURSPACE_ACESCG,
chromatic_adaptation_transform=cat
)
for space, cat in spaces
])
checker_rgb = cc_24_acescg()
# ocio_unit_rgb = [ 0.5, 0.4, -0.3]
return np.row_stack((camera_rgb, checker_rgb))
def generate_test_images():
rgb = generate_test_dataset()
rgb = rgb[np.newaxis, :].astype(np.float32)
ctl_root = "/Users/remi/ColorCode/aces-dev/transforms/"
ctl_ops = [
# AP0 to/from AP1 have been commented out
'ctl/lmt/LMT.Academy.GamutCompress.ctl',
]
ctl_args = [arg for op in ctl_ops for arg in ["-ctl", ctl_root + op]]
# Write reference
name_template = 'Gamut_Compress_{0}.exr'
colour.write_image(rgb, name_template.format('Reference'), bit_depth='float32')
# Write ctlrender version
subprocess.check_call(
[
'ctlrender',
'-force',
]
+ ctl_args +
[
name_template.format('Reference'),
name_template.format('CTLRender'),
'-format', 'exr32'
],
env=os.environ.update({'CTL_MODULE_PATH': ctl_root + '/ctl/lib'})
)
# Read and compare
RGB_In = colour.read_image(name_template.format('Reference'))[...,:3]
RGB_CTL = colour.read_image(name_template.format('CTLRender'))[...,:3]
np.set_printoptions(precision=11, floatmode='fixed')
print(RGB_In)
print(RGB_CTL)
if __name__ == '__main__':
generate_test_images()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment