Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
3D-PRO - About Rendering Engines Colourspaces Agnosticism
import numpy as np
import colour
from colour.utilities.verbose import message_box
name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005']
sRGB_w = colour.sRGB_COLOURSPACE.whitepoint
sRGB_XYZ_to_RGB = colour.sRGB_COLOURSPACE.to_RGB
sRGB_RGB_to_XYZ = colour.sRGB_COLOURSPACE.to_XYZ
adobe98_w = colour.ADOBE_RGB_1998_COLOURSPACE.whitepoint
adobe98_XYZ_to_RGB = colour.ADOBE_RGB_1998_COLOURSPACE.to_RGB
adobe98_RGB_to_XYZ = colour.ADOBE_RGB_1998_COLOURSPACE.to_XYZ
# Preparing *dark skin* colour in various colourspaces.
index, name, x, y, Y = data[0]
XYZ_r1 = colour.xyY_to_XYZ((x, y, Y))
# *sRGB* colourspace 0-255 values with OETF applied.
sRGB_rd1 = colour.XYZ_to_sRGB(XYZ_r1, illuminant)
# *sRGB* colourspace linear values.
sRGB_r1 = colour.XYZ_to_RGB(XYZ_r1,
illuminant,
sRGB_w,
sRGB_XYZ_to_RGB)
# *Adobe RGB 1998* colourspace linear values.
adobe98_r1 = colour.XYZ_to_RGB(XYZ_r1,
illuminant,
adobe98_w,
adobe98_XYZ_to_RGB)
message_box(('Reference "dark skin" "CIE XYZ" colourspace tristimulus '
'values:\n'
'\n\t{0}\n'
'"sRGB" colourspace values (OETF):\n'
'\n\t{1}\n'
'"sRGB" and "Adobe RGB 1998" colourspaces (Linear):\n'
'\n\tsRGB: {2}\n\tAdobe RGB 1998: {3}').format(
XYZ_r1,
np.around(sRGB_rd1 * 255),
sRGB_r1,
adobe98_r1))
# Preparing *green* colour in various colourspaces.
index, name, x, y, Y = data[13]
XYZ_r2 = colour.xyY_to_XYZ((x, y, Y))
# *sRGB* colourspace 0-255 values with OETF applied.
sRGB_rd2 = colour.XYZ_to_sRGB(XYZ_r2, illuminant)
# *sRGB* colourspace linear values.
sRGB_r2 = colour.XYZ_to_RGB(XYZ_r2,
illuminant,
sRGB_w,
sRGB_XYZ_to_RGB)
# *Adobe RGB 1998* colourspace linear values.
adobe98_r2 = colour.XYZ_to_RGB(XYZ_r2,
illuminant,
adobe98_w,
adobe98_XYZ_to_RGB)
message_box(('Reference "green" "CIE XYZ" colourspace tristimulus '
'values:\n'
'\n\t{0}\n'
'"sRGB" colourspace values (OETF):\n'
'\n\t{1}\n'
'"sRGB" and "Adobe RGB 1998" colourspaces (Linear):\n'
'\n\tsRGB: {2}\n\tAdobe RGB 1998: {3}').format(
XYZ_r2,
np.around(sRGB_rd2 * 255),
sRGB_r2,
adobe98_r2))
XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1,
sRGB_w,
illuminant,
sRGB_RGB_to_XYZ)
XYZ_adobe981 = colour.RGB_to_XYZ(adobe98_r1,
adobe98_w,
illuminant,
adobe98_RGB_to_XYZ)
message_box(('Converting back "dark skin" "CIE XYZ" colourspace '
'tristimulus values from "sRGB" and "Adobe RGB 1998" '
'colourspaces:\n'
'\n\tFrom sRGB: {0}\n\tFrom Adobe RGB 1998: {1}\n'
'\nEverything looks fine!').format(
XYZ_sRGB1, XYZ_adobe981))
sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * 1000
adobe98_m = adobe98_r1 * adobe98_r2 * adobe98_r2 * adobe98_r2 * 1000
XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m,
sRGB_w,
illuminant,
sRGB_RGB_to_XYZ)
XYZ_adobe98_m1 = colour.RGB_to_XYZ(adobe98_m,
adobe98_w,
illuminant,
adobe98_RGB_to_XYZ)
message_box(('Multiplying "dark skin" with "green" and converting back to '
'"CIE XYZ" colourspace tristimulus values from "sRGB" and '
'"Adobe RGB 1998" colourspaces:\n'
'\n\tFrom sRGB: {0}\n\tFrom Adobe RGB 1998: {1}\n'
'\nHouston? We have a problem!').format(
XYZ_sRGB_m1, XYZ_adobe98_m1))
ssh://vagrant@127.0.0.1:2222/home/vagrant/anaconda/envs/python2.7/bin/python -u /colour-science/colour/colour/examples/ramblings.py
===============================================================================
* *
* Reference "dark skin" "CIE XYZ" colourspace tristimulus values: *
* *
* [ 0.11518475 0.1008 0.05089373] *
* "sRGB" colourspace values (OETF): *
* *
* [ 115. 81. 68.] *
* "sRGB" and "Adobe RGB 1998" colourspaces (Linear): *
* *
* sRGB: [ 0.172906 0.08205715 0.05711951] *
* Adobe RGB 1998: [ 0.14702493 0.08205715 0.05814617] *
* *
===============================================================================
===============================================================================
* *
* Reference "green" "CIE XYZ" colourspace tristimulus values: *
* *
* [ 0.14985004 0.2318 0.07900179] *
* "sRGB" colourspace values (OETF): *
* *
* [ 66. 149. 76.] *
* "sRGB" and "Adobe RGB 1998" colourspaces (Linear): *
* *
* sRGB: [ 0.05440562 0.29876767 0.07183236] *
* Adobe RGB 1998: [ 0.12401962 0.29876767 0.08117514] *
* *
===============================================================================
===============================================================================
* *
* Converting back "dark skin" "CIE XYZ" colourspace tristimulus values *
* from "sRGB" and "Adobe RGB 1998" colourspaces: *
* *
* From sRGB: [ 0.11518475 0.1008 0.05089373] *
* From Adobe RGB 1998: [ 0.11518475 0.1008 0.05089373] *
* *
* Everything looks fine! *
* *
===============================================================================
===============================================================================
* *
* Multiplying "dark skin" with "blue" and converting back to "CIE XYZ" *
* colourspace tristimulus values from "sRGB" and "Adobe RGB 1998" *
* colourspaces: *
* *
* From sRGB: [ 0.86538968 1.58721208 0.20819516] *
* From Adobe RGB 1998: [ 0.63283056 1.47002564 0.14148678] *
* *
* Houston? We have a problem! *
* *
===============================================================================
Process finished with exit code 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.