Calculate colour temperature in K

dogmatic69 picture dogmatic69 · Dec 20, 2012 · Viewed 12k times · Source

I have written a lib for working with colours and stuck trying to calculate Tc(k). From what I have read working in the CIE 1931 XYZ colour space is the way to go and it can be obtained using xyY.

So far I have got everything correct to the point of figuring out the correct x and y from :

          X                 Y
x = ____________  y = ____________
    ( X + Y + Z)      ( X + Y + Z)

The numbers much up to the chart, but cant find anything that details how you go from x and y to Tc(K)

enter image description here

eg: For #FF0000 I get the following.

x: 0.64007449945677
y: 0.32997051063169

I have read a number of papers on the topic and litterally all the wikipedia articles. All the questions I have come across on SO simply link to a wiki article on colours, not seen one that has the actual formula for calculating Tc(k)

Answer

Tarmo picture Tarmo · Apr 12, 2014

Based on the Wikipedia article I entered the approximated formula for Color Temperature calculation into Excel as

=(-449*((R1-0,332)/(S1-0,1858))^3)+(3525*((R1-0,332)/(S1-0,1858))^2)-(6823,3*((R1-0,332)/(S1-0,1858)))+(5520,33)

R1 is color space x coordinate from 0 to 1
S1 is color space y coordinate from 0 to 1

Works fine!