![]() It’s also important to note that for purposes of fitting a curve to the data, green is best treated as two separate curves - one for temperatures below 6600 K, and a separate one for temperatures above that point.įrom here, I separated the data (without the “always 0” and “always 255” segments) into individual color components. Blue values above 6500 K are always 255.(Source: )įrom this, it’s easy to note that there are a few floors and ceilings that make our algorithm easier. The white point, as desired, occurs between 6500 K and 6600 K (the peak on the left-hand side of the chart). Again, these are based off the CIE 1964 10-degree CMFs. Mitchell Charity’s original Temperature (K) to RGB (sRGB) data, plotted in LibreOffice Calc. You can download my whole worksheet here in LibreOffice / OpenOffice. My first step in reverse-engineering a reliable formula was to plot Charity’s original blackbody values. ![]() The algorithm also does a great job of preserving the slightly yellow cast leading up to the white point, which is important for imitating daylight in post-production photo manipulation. Here’s a more detailed shot of the algorithm in the interesting photographic range, which is 1500 K to 15000 K:Īs you can see, banding is minimal - which is a big improvement over the aforementioned look-up table methods. The white point occurs at 6500-6600 K, which is perfect for photo manipulation purposes on a modern LCD monitor. Here’s the output of the algorithm from 1000 K to 40000 K: A discussion of the CIE 1931 2-degree CMF with Judd Vos corrections versus the 1964 10-degree set is way beyond the scope of this article, but you can start here for a more comprehensive analysis if you’re so inclined. Charity provides two datasets, and my algorithm uses the CIE 1964 10-degree color matching function. Special thanks to Mitchell Charityįirst off, I owe a big debt of gratitude to the source data I used to generate these algorithms - Mitchell Charity’s raw blackbody datafile at. (Actually, it’s way larger than most photographic situations call for.) While it will work for temperatures outside these ranges, estimation quality will decline. I’m presenting it here without math optimizations so as to not over-complicate it.Ĭaveat 3: this algorithm is only designed to be used between 1000 K and 40000 K, which is a nice spectrum for photography. ![]() It’s designed primarily for photo manipulation - so don’t try and use it for astronomy or medical imaging.Ĭaveat 2: due to its relative simplicity, this algorithm is fast enough to work in real-time on reasonably sized images (I tested it on 12 megapixel shots), but for best results you should apply mathematical optimizations specific to your programming language. Caveats for using this algorithmĬaveat 1: my algorithm provides a high-quality approximation, but it’s not accurate enough for serious scientific use. So I wrote my own algorithm, and it works pretty damn well. That might be a reasonable solution under certain circumstances, but when you factor in the additional XYZ -> RGB transformation required, it’s just too slow and overwrought for simple real-time color temperature adjustment. Unfortunately, that approach isn’t really a mathematical formula - it’s just glorified look-up table interpolation. Such algorithms seem to be based off AR Robertson’s method, one implementation of which is here, while another is here. Granted, there are some algorithms out there, but most work by converting temperature to the XYZ color space, to which you could add your own RGB transformation after the fact. Little did I know, but it’s pretty much impossible to find a reliable temperature to RGB conversion formula. ![]() This seemed like an easy algorithm to find, since many photo editors provide tools for correcting an image’s color temperature in post-production, and every modern camera - including smartphones - provides a way to adjust white balance based on the lighting conditions of a shot.Įxample of a camera white balance screen. While working on a “Color Temperature” tool for PhotoDemon, I spent an evening trying to track down a simple, straightforward algorithm for converting between temperature (in Kelvin) and RGB values. If you don’t know what “color temperature” is, start here. Converting temperature (Kelvin) to RGB: an overview
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |