We can estimate a color temperature for a given color. However, the estimate is most useful when the color is close to white or the black body curve. The color temperature, known as the CCT, is just one particular aspect of a color and its light quality.
For more detailed information, please check the article by Waveform Lighting, https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates. The article will be listed in the Sources section at the end of this blog entry.
The program RGBTEMP will estimate CCT from a color given its RGB (red-green-blue) coordinates.
The calculation involves several steps:
1. Scaling RGB values from a scale of 0-255 to 0-1. This is accomplished by dividing each of the parameters of the color’s RGB value by 255. Standard RGB values (sRGB) are used.
2. The scaled RGB values will be converted to CIE 1931 XYZ color space values. In 19031, the International Commission on Illumination created the CIE 1931 color space, designed to describe how the distribution of color wavelengths affect how colors are perceived. The conversion is done in two parts.
2a. Adjust each of the scaled RGB values to account for the gamma correction:
Let I be the scaled parameter for R, G, and B. Then:
If I ≤ 0.04045, Then:
I_adj = I/12.92
I_adj = ( (I + 0.055) / 1.055) ^ 2.4
2b. Calculate the XYZ values. This can be accomplished by matrix multiplication:
[ [ X ] [ Y ] [ Z ] ] =
[[ 0.4124, 0.3576, 0.1805 ] [ 0.2126, 0.7152, 0.0722 ] [ 0.0193, 0.1192, 0.9504 ]]
* [ [ R ] [ G ] [ B ] ]
3. With the XYZ coordinates, calculate CIE Yxy coordinates. Y is already done, so only (small) x and (small) y are needed:
x = X / (X + Y + Z)
y = Y / (X + Y + Z)
4. Calculate the CCT. There are several methods: one of them is a cubic approximation from Calvin McCamy:
n = (x – 0.3320) / (0.1858 – y)
CCT = 437 * n^3 + 3601 * n^2 + 6861 * n + 5517
CCT is in Kelvins.
TI-84 Plus Program RGBTEMP
Disp “COLOR TEMP FROM RGB”
Input “RED :”,R
Input “GREEN :”,G
Input “BLUE :”,B
Disp “CCT (K):”,C
HP Prime Program RGBTEMP
The HP Prime version returns CCT, the XYZ coordinates, and the x and y parameters in a four element list.
// 2019-07-11 EWS
// RGB to color temperature
FOR I FROM 1 TO 3 DO
IF M0(I,1)≤0.04045 THEN
// RGB to CIE XYZ 1931
// XYZ to Yxy
// xy to CCT (Kelvins)
// McCamy approximation
(CCT rounded to four decimal places)
Remember the closer to the Black Body Curve, the more accurate the answer.
Red: RGB (255, 0, 0)
CCT: 3034.8988 K
Green: RGB (0, 255, 0)
CCT: 6068.7576 K
Orange: RGB (255, 165, 0)
CCT: 2429.5395 K
Sky Blue: RGB (136, 206, 235)
CCT: 13207.1056 K
White: RGB (255, 255, 255)
CCT: 6506.6551 K
“Convert color data into different standards and color spaces” and “Color math and programming code examples” EASYRGB. IRO Group Limited. 2019. https://www.easyrgb.com/en/convert.php and https://www.easyrgb.com/en/math.php Retrieved July 11, 2019
“Calculate color temperature (CCT) from CIE 1931 xy coordinates” Waveform Lighting. 2019. https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates Retrieved July 6, 2019
“sRGB” Wikipedia. Last edited May 18, 2019. https://en.wikipedia.org/wiki/SRGB
Retrieved June 16, 2019.
All original content copyright, © 2011-2019. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.