Skip to content

Instantly share code, notes, and snippets.

@rasmusbonnedal
Created October 26, 2022 10:30
Show Gist options
  • Save rasmusbonnedal/db4cae2693092eceeb3513b257a30df8 to your computer and use it in GitHub Desktop.
Save rasmusbonnedal/db4cae2693092eceeb3513b257a30df8 to your computer and use it in GitHub Desktop.
import numpy as np
"""
From Aces 1.2
Rec.709 from reference
- !<MatrixTransform> {matrix: [0.952552, 0, 9.36786e-05, 0, 0.343966, 0.728166, -0.0721325, 0, 0, 0, 1.00883, 0, 0, 0, 0, 1]}
- !<MatrixTransform> {matrix: [3.2096, -1.55743, -0.495805, 0, -0.970989, 1.88517, 0.0394894, 0, 0.0597193, -0.210104, 1.14312, 0, 0, 0, 0, 1]}
Adobe RGB from reference
!<MatrixTransform> {matrix: [1.72456, -0.419994, -0.304567, 0, -0.27648, 1.37272, -0.0962392, 0, -0.0261255, -0.0901748, 1.1163, 0, 0, 0, 0, 1]}
"""
rec709_1 = np.array([0.952552, 0, 9.36786e-05, 0, 0.343966, 0.728166, -0.0721325, 0, 0, 0, 1.00883, 0, 0, 0, 0, 1]).reshape(4, 4)[:3, :3]
rec709_2 = np.array([3.2096, -1.55743, -0.495805, 0, -0.970989, 1.88517, 0.0394894, 0, 0.0597193, -0.210104, 1.14312, 0, 0, 0, 0, 1]).reshape(4, 4)[:3, :3]
aces_to_rec709 = rec709_2 @ rec709_1
aces_to_adobergb = np.array([1.72456, -0.419994, -0.304567, 0, -0.27648, 1.37272, -0.0962392, 0, -0.0261255, -0.0901748, 1.1163, 0, 0, 0, 0, 1]).reshape(4, 4)[:3, :3]
adobergb_to_aces = np.linalg.inv(aces_to_adobergb)
adobergb_to_rec709 = aces_to_rec709 @ adobergb_to_aces
print("Adobe RGB to Rec.709", adobergb_to_rec709)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment