hanno
hanno

Reputation: 6513

Image color saturation

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); 

Upvotes: 3

Views: 1536

Answers (1)

Miguel Grinberg
Miguel Grinberg

Reputation: 67499

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.

Upvotes: 2

Related Questions