3
votes

Though I have found a lot of topics on color tint and temperature, but till now I have not seen any definite solution, which is the reason I am creating this post..My apologies for that.

I am interested in adjusting color temp and tint in images from RGB values, somewhat similar to the iPhoto application found in iOS where it can be adjusted with a slider bar from left to right. Whatever I have found, temp and tint are orthogonal properties, where temp adjustment is along the blue (left; cool colors)--yellow(right; warm colors) and tint along the green (left) -- magenta (right) axis. How do I adjust them using formulas from RGB values i.e., uderlying implementation of the color temp and tint slider bars. I can convert them to HSV space and then I can rotate the hue wheel channel towards those (blue, yello, green, magenta) angles, but how to do them in a systematic fashion similar to the slider bar implementation by changing gradually from low level (middle of the slider bar) to high level (right/left ends of the slider bar).

Thanks!

2

2 Answers

0
votes

You should try using HSL instead of HSV. HSL saturation separates itself from the hue and luminosity has very definitive range when it comes to mathematical calculation.

In HSL, to add tint you move the L factor between 50-100 and to add shade the L factor varies between 0-50. Also saturation for HSL controls the tone directly unlike HSV.

For temperature, you have to devise your own stratagy changing the color between red and blue but one golden hint that I can give you is "every pure RGB color has one of 3 color values as zero, second fixed to 255 and 3rd varies with the factor of 255/60.

Hope this helps-

0
votes

Whereas color temparature is a physical value, its expression in terms of RGB values not trivial. If all you need is a pair of orthogonal axes in the RGB colorspace for the visual adjustment of white balance, they can be defined with relative ease in such a way as to resemble the true color temperature and its derivative the tint.

Let us name our RGB temperature BY—for the balance between blue and yellow, and our RGB tint GR—for the balance balance between green and red. Now, these functions must satisfy the following obvious requirements:

  1. They shall not depend on brightness, or be invariant to multiplication of all the RGB components by the same factor:

     BY(r,g,b) = BY(kr, kg, kb),
     GR(r,g,b) = GR(kr, kg, kb).
    
  2. They shall be zero for neutral gray:

     BY(0,0,0) = 0,
     GR(0,0,0) = 0.
    
  3. They shall belong the to same range, symmetrical around zero point. I will use [-1..+1]

  4. Any combination of BY and GR shall define a valid color.

Now, one of the ways to define them could be:

BY = (r + g - 2b)/(r + g + 2b),
GR = (r - g     )/(r + g)     .

so that each pair of BY and GR determines a specific proportion

r:g:b = (1 + BY)(1 + GR)
        (1 + BY)(1 - GR)
         1 - BY

The following image shows the colors of maximum brightness on our BY-GR plane. BY is directed right, GR down, and the neutral point (0,0) is at the center:

enter image description here

Proper adjustment of white balance consists of multiplication of the linear RGB values by individual factors:

r_new = wb_r * r_old
g_new = wb_g * g_old
b_new = wb_b * b_old

It happens to work on gamma-compressed RGB too, but not so well on sRGB, because of a piece-wise definition of its transfer function, but the distortion will be small and often unnoticeable. If you want a perfect adjustment, however, make sure to work in linear RGB.

Once a BY-GR pair is chosen and the corresponding RGB proportion calculated, only one degree of freedom remains—the overall multiplier (see req. 1). Choose it so that no pixels become clipped.