3

I was trying to find a functional form for saturation but didn't find anything. It can't be that hard but all my guesses don't look quite right (the direction towards desaturation seems easier).

I have the pixel data of the image in RGB format. The final image should also be in RGB format. So, how are these functions defined:

r_n = saturation_r(r,g,b,sat);
g_n = saturation_g(r,g,b,sat);
b_n = saturation_b(r,g,b,sat); 
hanno
  • 6,401
  • 8
  • 48
  • 80
  • What does the `sat` argument mean? Are you taking a RGB color as input and then outputting the same color with the saturation changed to `sat`? Are you looking for a function to convert RGB to HSL, or do you already know how to do that? There's a good wikipedia entry on HSV and HSL transformations. – Brian L Dec 07 '11 at 05:43

1 Answers1

2

Convert the RGB pixel to HLS, scale the S by your sat input, then convert back to RGB. Pseudo-code, assuming all color components are in the range 0.0 to 1.0:

rgb_to_hls(r, g, b, h, l, s);
s = s * sat
hls_to_rgb(h, l, s, r, g, b);
return r, g, b

If you need RGB/HLS conversion functions, here they are.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152