Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate colour temperature in K

Tags:

c

php

colors

gimp

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)

like image 905
dogmatic69 Avatar asked Dec 20 '12 15:12

dogmatic69


People also ask

How is color temperature calculated?

M(λ,T)=c1λ−5(ec2/(λT)-1)−1, where constant c1 = 3.741832 × 10−16 Wm2 and c2 = 1.4388 × 10−2 m K. The color temperature T of a light source is the color temperature of a Planckian radiator which emits radiation of the same chromaticity as the light source.

What is actual color temperature K?

Colour temperature is measured in Kelvin (K) – the lower the number, the warmer the white light appears, while a higher Kelvin will appear cooler. Colour temperature generally ranges from 2700-3300K (warm) to 3300-5300 (cool) – and 6500K is daylight.

What is K in RGB?

Temperature. K. Color: rgb(255,108, 0) Hex: #FF6C00.

Why is color temperature measured in Kelvin?

The color temperature model is based on the relationship between the temperature of a theoretical standardized material, called a black body radiator, and the energy distribution of its emitted light as the radiator is brought to increasingly higher temperatures, measured in Kelvin (K).


2 Answers

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!

like image 69
Tarmo Avatar answered Oct 09 '22 03:10

Tarmo


If I understand you correctly please see this pdf where a number of methods (briefly :( ) described. From this PDF:

[CCT1] Calculations are performed using CIE 1960 uniform color space coordinates u and v. Coordinates u and v are derived from x and y using the formulae: u = 4x/(12y-2x+3) and v = 6y/(12y-2x+3) The correlated color temperature is defined as the temperature of a blackbody that lies closest to the u,v coordinates of the test source. Two separate methods provide results: one is an iterative method based on the definition, and the other is the commonly used Robertson’s method involving interpolation based on a table of 30 pre-calculated u, v and inverse-slope parameters. Iteration If uS and vS are the values for a test source, and uT and vT are the blackbody values at temperature T, the correlated color temperature is the value of T where:

sqrt( (uS - uT)^2 + (vS - vT)^2 )

is minimized. Adjusting the temperature T to obtain the minimum of this function was done using spreadsheets (Quattro Pro 8 and Excel 97). Both spreadsheets gave identical values.

Don't know if it actually helps you.

like image 1
maverik Avatar answered Oct 09 '22 04:10

maverik