Jump to content
  • Advertisement
Sign in to follow this  
dnaxx

Change color saturation

This topic is 2395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am using the HSL color model to change the saturation of an image using the following steps:
  • Convert RGB image to HSL model
  • Change saturation component of HSL image <-- Problem
  • Convert back to RGB modelThe conversion seems to work fine. Changing hue works like it should by adding the hue change in degrees and wrapping the final value in the range of 0 to 360 degrees. But how can I change the saturation (very much like the way it is possible in Adobe Photoshop)? The change of saturation is given in the range of [-1,1] where -1 is no saturation and 1 is 100% saturation.

    Regards,

Share this post


Link to post
Share on other sites
Advertisement
After some experiments I found the solution: saturation and brightness are not added but multiplied.

Share this post


Link to post
Share on other sites
Saturation:
// get luminance
float lumi = color.r * 0.33f + color.g * 0.51f + color.b * 0.11f;
// Mix between original and grayscaled color. 0 = not saturated at all, 1 = max saturated
float saturatedColor = lerp( color.rgb , lumi, _somefactor_ );

Not sure if the math is 100% correct, but it works pretty well. If you like you can multiply the "lumi" in the lerp function with a custom color to colorize towards blueish, sepia, or whatever you whish.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!