0

I have a picture(RGB) and i wanna adjust color temperature, like in Lightroom. I try converting RGB to LAB and adjust B channel, but it's wrong. May be someone can help with sample code or algorithm of color temperature implementation? Like this:

rgb temperature(int temp, rgb color);

where value - temperature, color - input color (from image), return value - output color (adjusted)

Now, I use this algorithm. RGBtoLAB and LABtoRGB I took from: http://www.easyrgb.com/index.php?X=MATH&H=01#text1

for (int i = 0; i < img.pixCount; i++)
{
    lab32f lab = RGBtoLAB(img.getPixel(i));  
    lab.b += temp.value;  // -100..100
    img.setPixel(i, LABtoRGB(lab));
}

Result images:

Result images

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Torvald
  • 3
  • 3
  • Show us your code. Also, explain what "it's wrong" means. You need to tell us what your input is, how you're converting, what your actual output is and what your expected output is. Otherwise we can't really help. – Jim Mischel Jun 24 '16 at 14:52
  • The first thing I would do is verify that given an RGB value, if you convert it to LAB and back to RGB, you get back the initial value. That is, `LABtoRGB(RGBtoLAB(x)) == x`. If that doesn't work, then you need to fix it. If it works, then perhaps you're misunderstanding how color temperature is represented in the LAB space. I'm not familiar with that, so I can't say. – Jim Mischel Jun 24 '16 at 16:21
  • Also, the page you link doesn't have an RGB -> LAB converter. Are you converting to an intermediate representation first? – Jim Mischel Jun 24 '16 at 16:23
  • `LABtoRGB(RGBtoLAB(x)) == x` - it's true. I converting like this: RGB -> XYZ -> LAB – Torvald Jun 24 '16 at 16:40
  • Does your RBGtoLAB function provide the same results as http://colormine.org/convert/rgb-to-lab? Also, what will happen if `lab.b + temp.value` goes outside the range of -100..100? Or is it `temp.value` that's supposed to be in that range? Are you sure you have the formula for increasing the temperature correct? – Jim Mischel Jun 24 '16 at 17:17
  • I don't know about range. I'm not sure, I think all of my algorithm is wrong. – Torvald Jun 24 '16 at 17:45
  • this may be of a bit of help http://stackoverflow.com/q/33769111/2521214 – Spektre Jun 24 '16 at 19:00
  • Take a look at this [link](http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/). – Adi Shavit Jun 24 '16 at 20:14

0 Answers0