以K为单位计算色温 [英] Calculate colour temperature in K

查看:1642
本文介绍了以K为单位计算色温的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个库来处理颜色,并试图计算 Tc(k)。根据我在。



转换为php,这是什么我到目前为止:

  $ temp = array(9500,7000,5500,3750,3000,2700,2250,1800, 1500); 
$ hex = array('9DBEFF','E4EEFF','FFE4BE','FFA04C','FF7A26','FF6A19','FF500B','FF3403','FF2300')

echo'< h3> K - > RGB< / h3>';
foreach($ temp as $ k){
$ rgb = ColourConverter :: temperature2rgb($ k);
echo sprintf('< div style =background-color:rgb(%s); text-align:center; width:100px; height:25px; clear:both;>%s< / div ;',implode(',',$ rgb),$ k);
}

echo'< h3> RGB - > K h 3';
foreach($ hex as $ v){
$ rgb = array_values(ColourConverter :: hex2rgb($ v));
$ k = round(ColourConverter :: rgb2temperature($ rgb [0],$ rgb [1],$ rgb [2]));
echo sprintf('< div style =background-color:rgb(%s); text-align:center; width:100px; height:25px; clear:both;>%s< / div ;',implode(',',$ rgb),$ k);
}



我的输出:





很接近但不是100%。 (在我的代码中找到错误,现在几乎完美)




  • 颜色稍微偏离k - > rgb

  • 它不工作k - > rgb - > k。您不能恢复到相同的值。



代码



UFRaw line〜234



我的php转换


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)

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)

解决方案

I done some digging in some open source apps and found something in UFRaw. I have not quite figured out what is going on exactly.

Also found a paper that seems to cover the topic quite well.

Converted to php and this is what I have so far:

$temp = array(9500, 7000, 5500, 3750, 3000, 2700, 2250, 1800, 1500);
$hex = array('9DBEFF', 'E4EEFF', 'FFE4BE', 'FFA04C', 'FF7A26', 'FF6A19', 'FF500B', 'FF3403', 'FF2300');

echo '<h3>K -> RGB</h3>';
foreach ($temp as $k) {
    $rgb = ColourConverter::temperature2rgb($k);
    echo sprintf('<div style="background-color:rgb(%s); text-align: center; width: 100px; height: 25px; clear: both;">%s</div>', implode(', ', $rgb), $k);
}

echo '<h3>RGB -> K</h3>';
foreach ($hex as $v) {
    $rgb = array_values(ColourConverter::hex2rgb($v));
    $k = round(ColourConverter::rgb2temperature($rgb[0], $rgb[1], $rgb[2]));
    echo sprintf('<div style="background-color:rgb(%s); text-align: center; width: 100px; height: 25px; clear: both;">%s</div>', implode(', ', $rgb), $k);
}

My output:

Pretty close but not 100% yet. (Found a bug in my code and it is now almost perfect)

  • The colours are slightly off going from k -> rgb
  • It does not work doing k -> rgb -> k. You don't get back to the same value.

Code

UFRaw line ~234

my php conversion

这篇关于以K为单位计算色温的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆