Colour Temperature Ramblings

User Defined Illuminant

In [1]:
import colour  # Importing the API namespace.
from colour.plotting import *  # Importing all the plotting objects.

# Defining some convenient shortcuts variables.
sRGB_w = colour.sRGB_COLOURSPACE.whitepoint  # *CIE Standard Illuminant D Series* *D65*.
sRGB_XYZ_to_RGB = colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix
sRGB_RGB_to_XYZ = colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix
sRGB_oecf = colour.sRGB_COLOURSPACE.transfer_function  # Opto-electronic conversion function from *CIE XYZ* to *RGB*.
sRGB_inverse_oecf = colour.sRGB_COLOURSPACE.inverse_transfer_function  # Opto-electronic conversion function from *CIE XYZ* to *RGB*.

# Retrieving *CIE Standard Illuminant E* chromaticity coordinates.
# E = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['E']
E = colour.ILLUMINANTS['cie_2_1931'][
    'E']  # Accessing the data using a convenient alias.

# Defining a 50% gray *sRGB* colour.
RGB = (0.5, 0.5, 0.5)

# Converting the 50% gray colour to *CIE XYZ*, under the *CIE Standard Illuminant E*.
XYZ = colour.RGB_to_XYZ(RGB,
                        sRGB_w,
                        E,
                        sRGB_RGB_to_XYZ,
                        'CAT02',
                        sRGB_inverse_oecf)

# Defining a convenient function to perform *temperature* change.
def temperature(XYZ, illuminant):
    return colour.XYZ_to_RGB(XYZ,
                             E,
                             illuminant,
                             sRGB_XYZ_to_RGB,
                             'CAT02',
                             sRGB_oecf)

# Plotting various colour patches to illustrate the *temperature* change using
# a given illuminant.
multi_colour_plot(
    (colour_parameter('Gray "Original"', RGB),
     colour_parameter('Gray "A"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['A'])),
     colour_parameter('Gray "B"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['B'])),
     colour_parameter('Gray "C"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['C'])),     
     colour_parameter('Gray "D50"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['D50'])),
     colour_parameter('Gray "D55"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['D55'])),
     colour_parameter('Gray "D60"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['D60'])),
     colour_parameter('Gray "D65"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['D65'])),
     colour_parameter('Gray "D75"',
                      temperature(XYZ,
                                  colour.ILLUMINANTS['cie_2_1931']['D75']))),
    text_size=16)
/home/vagrant/anaconda/envs/python2.7/lib/python2.7/site-packages/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))
Out[1]:
True

Using Correlated Colour Temperature

In [2]:
def CCT_to_xy(CCT, tint=0):
    return colour.UCS_uv_to_xy(colour.CCT_to_uv_ohno2013(CCT, tint / 6000))

# Plotting various colour patches to illustrate the *temperature* change using
# a given correlated colour temperature and tint.
multi_colour_plot(
    (colour_parameter('Gray "Original"', RGB),
     colour_parameter('Gray "3K"',
                      temperature(XYZ,
                                  CCT_to_xy(3000))),
     colour_parameter('Gray "4K"',
                      temperature(XYZ,
                                  CCT_to_xy(4000))),
     colour_parameter('Gray "5K"',
                      temperature(XYZ,
                                  CCT_to_xy(5000))),     
     colour_parameter('Gray "6K"',
                      temperature(XYZ,
                                  CCT_to_xy(6000))),
     colour_parameter('Gray "7K"',
                      temperature(XYZ,
                                  CCT_to_xy(7000))),
     colour_parameter('Gray "8K"',
                      temperature(XYZ,
                                  CCT_to_xy(8000))),
     colour_parameter('Gray "9K"',
                      temperature(XYZ,
                                  CCT_to_xy(9000))),
     colour_parameter('Gray "10K"',
                      temperature(XYZ,
                                  CCT_to_xy(10000))),
     colour_parameter('Gray "6K, -150T"',
                      temperature(XYZ,
                                  CCT_to_xy(6000, -150.))),
     colour_parameter('Gray "6K, 0T"',
                      temperature(XYZ,
                                  CCT_to_xy(6000, 0))),
     colour_parameter('Gray "6K, 150T"',
                      temperature(XYZ,
                                  CCT_to_xy(6000, 150.)))),
    text_size=8)
Out[2]:
True