Last active
August 29, 2015 14:17
-
-
Save KelSolaar/e8c29b1eadf5afa8dddd to your computer and use it in GitHub Desktop.
RGB Colourspace Whitepoint Change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:98b4f38bd43ca2878bb71f905d912912007797b6023387b28ad4667390771111" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"RGB Colourspace Whitepoint Change" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"import colour\n", | |
"\n", | |
"NUKE_TEMPLATE = \"\"\"\n", | |
" ColorMatrix {{\n", | |
" inputs 0\n", | |
" matrix {{\n", | |
" {0}\n", | |
" }}\n", | |
" name {1}\n", | |
" selected true\n", | |
" }}\n", | |
"\"\"\"\n", | |
"\n", | |
"def nk_format_matrix(M, precision=7):\n", | |
" pretty = lambda x: ' '.join(\n", | |
" map('{{:0.{}f}}'.format(precision).format, x))\n", | |
"\n", | |
" nk = '{{{0}}}\\n'.format(pretty(M[0]))\n", | |
" nk += '\\t {{{0}}}\\n'.format(pretty(M[1]))\n", | |
" nk += '\\t {{{0}}}'.format(pretty(M[2]))\n", | |
" return nk\n", | |
"\n", | |
"COLOURSPACE = colour.sRGB_COLOURSPACE\n", | |
"\n", | |
"W_R_N = 'D65'\n", | |
"W_T_N = 'D75'\n", | |
"\n", | |
"W_R = colour.ILLUMINANTS['cie_2_1931'][W_R_N]\n", | |
"W_T = colour.ILLUMINANTS['cie_2_1931'][W_T_N]\n", | |
"\n", | |
"CAT = colour.chromatic_adaptation_matrix_VonKries(\n", | |
" colour.xy_to_XYZ(W_R),\n", | |
" colour.xy_to_XYZ(W_T),\n", | |
" transform='XYZ Scaling')\n", | |
"\n", | |
"M = np.dot(COLOURSPACE.XYZ_to_RGB_matrix,\n", | |
" np.dot(CAT, COLOURSPACE.RGB_to_XYZ_matrix))\n", | |
"\n", | |
"print(NUKE_TEMPLATE.format(nk_format_matrix(M),\n", | |
" '{0}_to_{1}_ColorMatrix'.format(W_R_N, W_T_N)))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
" ColorMatrix {\n", | |
" inputs 0\n", | |
" matrix {\n", | |
" {0.9977895 -0.0083660 -0.0602694}\n", | |
"\t {0.0003985 1.0008830 0.0051166}\n", | |
"\t {0.0025633 0.0158961 1.1268520}\n", | |
" }\n", | |
" name D65_to_D75_ColorMatrix\n", | |
" selected true\n", | |
" }\n", | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"CAT = colour.chromatic_adaptation_matrix_VonKries(\n", | |
" colour.xy_to_XYZ(W_R),\n", | |
" colour.xy_to_XYZ(W_T),\n", | |
" transform='CAT02')\n", | |
"\n", | |
"NPM_i = np.linalg.inv(colour.normalised_primary_matrix(\n", | |
" COLOURSPACE.primaries, W_T))\n", | |
"\n", | |
"M = np.dot(NPM_i,\n", | |
" np.dot(CAT, COLOURSPACE.RGB_to_XYZ_matrix))\n", | |
"\n", | |
"print(NUKE_TEMPLATE.format(nk_format_matrix(M),\n", | |
" '{0}_to_{1}_NPM_ColorMatrix'.format(W_R_N, W_T_N)))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
" ColorMatrix {\n", | |
" inputs 0\n", | |
" matrix {\n", | |
" {1.0470997 -0.0433275 -0.0037723}\n", | |
"\t {0.0020709 0.9978452 0.0000839}\n", | |
"\t {0.0030194 0.0152122 0.9817683}\n", | |
" }\n", | |
" name D65_to_D75_NPM_ColorMatrix\n", | |
" selected true\n", | |
" }\n", | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 2 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment