Not Your Everyday Banana

by Bart Arondson

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

I'm wondering how to convert programmatically (i.e. with a programming language rather than an editor) from one colour temperature to another?

If, for example, I make the assumption (and it's a big assumption) that a white balance algorithm could take a processed image (e.g. JPEG, etc.) and place the overall temperature in a scene at 6500, how would you algorithmically "cool" or "warm" the scene to a specific temperature?

Obviously this is a common operation in an image editing program, but these typically operate on RAW images which have no processing applied (colour space manipulation or otherwise). In the case of RAW files, perhaps the individual RAW files contain sufficient information (in the file header) regarding the colour calibration of the camera sensor to make the specific temperature transformation more deterministic?

By the way, I asked this question on the regular Stack Overflow and it was suggested I may get a better answer here.

share|improve this question
    
"[…] perhaps the individual RAW files contain sufficient information (in the file header) regarding the colour calibration of the camera sensor to make the specific temperature transformation more deterministic?" Yes. The example is for Canon's raw, so the location differs a bit for other brands. –  koiyu May 20 '11 at 11:36
    
Thanks that was a very useful link! Though I'm still unsure of how to change from one colour temperature to another? –  trican May 20 '11 at 12:16
    
Raw images are always interpreted with some instruction set of which the Exif info on white balance RGGB levels are one aspect. JPGs in turn are more or less composite images in which all the info is hardcoded and edits are destructive. I can't provide good examples, but I'd dive into ImageMagick which is a command line image editor with several program interfaces. Its -color-matrix option might get you started; see also: fmwconcepts.com/imagemagick/whitebalance/index.php –  koiyu May 20 '11 at 13:43
add comment

1 Answer 1

up vote 4 down vote accepted

You would need to do a color space white point conversion in L*a*b* space. Most color models that we normally work with, primarily RGB but often CMYK, are designed to support the limitations and requirements of physical hardware. Those models usually don't represent the "perceptual" space of color very well, though, and white point is definitely a perceptual aspect of color.

Whenever you need to apply perceptual adjustments to an image, such as color temperature or tint shifts, it is best done by converting from RGB to XYZ, and during the conversion, you can apply "reference white points" for the source and destination color space. Conversion from XYZ to Lab then gets you into a color space where you can perceptually remap the white point and all the colors such that they maintain continuity.

Color space conversions, chromatic adaptation, white point adjustments, etc. are rather complex mathematically. The more perceptually accurate you intend to be, the more complex the math usually ends up. An excellent source of information for color space conversions can be found at Bruce Lindbloom's web site. Some additional useful information can be found on Wikipedia. You might also find this information on CIE's D-Series Illuminants useful, as it contains white point specific information, calculations, and constants.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.