# How to Calculate the Color Temperature / Tint of the Colors in an Image?

How can I calculate the (black body equivalent) color temperature of the light source illuminating a given image? Below are screenshots of Adobe Lightroom manipulating color temperature and a shift in the RGB Histograms. Given RGB components of the image, how do I go about calculating it? I should expect a single value - The black body equivalent temperature of the illumination source, right?

• I'm not sure that makes sense. Color temperature is a property of light, like the lamps used to illuminate a scene while the image is being taken. I don't know if images themselves have a color temperature. Like, what's the color temperature of a plain green image? Green isn't even in the blackbody spectrum. Was it produced by a dark green object illuminated by a high temperature source, or a light green object illuminated by a low temperature source? May 2, 2013 at 15:28
• The last part of my question - " I should expect a single value - The black body equivalent temperature of the illumination source, right?" Have I been unclear? If so, please feel free to suggest edits. If you have a green surface, it shall look different depending on the illumination source. I am trying to see the green and compute the (black body equivalent) temperature of the illumination source - How do Photoshop and Light Room do it?. Even a plain green object shall not appear as - #00FF00 (rgb hex). May 2, 2013 at 18:32
• @endolith - I made some changes. Do you think the question is clearer now? May 2, 2013 at 18:38
• Ok, that makes more sense, but I'm still not sure it's possible. Can't two shades of green illuminated by different color temperature sources produce identical output images? So how can you tell the illuminant's color temperature without knowing the properties of the object and the camera? May 2, 2013 at 19:32
• @endolith - Can it? I am not sure. I think it might. Cameras have built in White balance control. But most images have multiple shades and this seems to be analyzed with histograms - stochastically. So there might be a confidence interval of being at a particular temperature. Besides, cameras and pictures have some meta data too. I have a feeling that the equation for this is expert drive - someone (expert) calibrated it to give a number. Just like *C or *F - Who decided that freezing point of water shall be set to 0*C or 32*F? May 2, 2013 at 19:45

This paper (pdf download/updated link) gives the following formulae for calculating Correlated Color Temperature (CCT). They do not explicitly say (or I missed it), but their example leads me to infer that they are assuming RGB values in the range of 0-255.

1. Convert the RGB values to CIE tristimulus values (XYZ) as follows:

$$X = (-0.14282)(R) + (1.54924)(G) + (-0.95641)(B)$$ $$Y = (-0.32466)(R) + (1.57837)(G) + (-0.73191)(B) = Illuminance$$ $$Z = (-0.68202)(R) + (0.77073)(G) + (0.56332)(B)$$

2. Calculate the normalized chromaticity values:

$$x = X/(X+Y+Z)$$ $$y = Y/(X+Y+Z)$$

3. Compute the CCT value from:

$$CCT = 449n^3 + 3525n^2 + 6823.3n + 5520.33$$

$$\text{where }n = (x − 0.3320) / (0.1858 − y)$$

Which can be combined to form the following equation:

$$CCT = 449n^3 + 3525n^2 + 6823.3n + 5520.33$$ $$\text{where }n = ((0.23881)R+(0.25499)G+(-0.58291)B) / ((0.11109)R+(-0.85406)G+(0.52289)B)$$

I am not sure about applying this to an image, but if you just want a single, generalizing number, than you could perhaps use some sort of averaging? Either find an acceptable "average" RGB value for the image (eg. the centroid) and use that to calculate a temperature or (a much more computationally expensive option) calculate the temperature for each pixel in the image and take the average of those results.

Also, bear in mind that CCT is only an approximate metric for most colors, since only a single curve in the color space actually represents color which can be obtained from a real world black body radiator. Thus for all other colors, the calculated color temperature is simply an approximation of the black body temperature it most closely represents. Thus, for some colors (especially greens) it can actually be a somewhat meaningless value, at least in a physical sense. This is illustrated well in the following image (from the wikipedia article on color temperature).

The black line in the image represents the Planckian Locus of colors which could actually be produced by block body radiation. The smaller crossing lines represent the isotherms of the CCT approximation nearby.

Also, since your question specifically references Adobe Lightroom, I found this while searching around:

The sliders [in Adobe Lightroom] adjust not the black body temp of the light, but the compensation applied to the image to compensate for the black body temp of the light. This goes the other way round.

So bear in mind that the color temperature you see on the Lightroom slider will not be the same as those calculated from the above formulae.

• Please be advised that the RGB-XYZ transform used above appears to be specific to the colour space used by a certain hardware. It is most certainly not correct for sRGB, which is what is most probably being used in OP's case. Refer to the correct transforms in the sRGB standard Dec 26, 2014 at 20:05
• Note also that the Y component in CIE 1931 denotes luminance, as opposed to illuminance Dec 26, 2014 at 22:39
• I've calculated some colors according to your formulae, and as I see in some cases it works, while in some other cases - such as red (255 0 0) and blue (0 0 255) - it gives wrong answer: - white (255 255 255): n = 0.4049, CCT = 8890.77 K -> seems to be correct - yellow (255 255 0): n = -0.6646, CCT = 2410.65 K -> seems to be correct - green (0 255 0): n = -0.2986, CCT = 3785.42 K -> seems to be correct - cyan (0 255 255): n = 0.9902, CCT = 16168.7 K -> seems to be correct - magenta (255 0 255): n = -0.5428, CCT = 2783.54 K -> seems to be correct Jan 10, 2015 at 15:58
• I updated the broken link; as @awdz9nld suspected, the paper is intended for "Calculating Color Temperature and Illuminance using the TAOS TCS3414CS Digital Color Sensor" which is a specialized (and outdated) proprietary camera component. Aug 23, 2021 at 4:04
• Continuation of @Tamas's comment: however: red (255 0 0): n = 2.1497, CCT = 40938.6 K -> seems to be wrong blue (0 0 255): n = -1.1148, CCT = 1672.45 K -> seems to be wrong
– Peter K.
Aug 23, 2021 at 15:05