I know there is formula for going RGB -> Luminance, but I need given a brightness parameter to modify the RGB values of an image. How do I do that?
Thanks
I know there is formula for going RGB -> Luminance, but I need given a brightness parameter to modify the RGB values of an image. How do I do that?
Thanks
My recommendation would be the same as ChrisA.'s answer, with one difference:
Use the HSP color space instead, as it is an approximation of Photoshop's algorithm and has better results.
For the sake of not just linking to HSP's site (which frankly should be more than enough; it's just that I don't like to answer without examples), here is my
C#
implementation, which follows the site's:Adding to Mark Ransom's Answer: It would be better to use the said factor with a 255 constant and add it to the current color-value:
If you just do with a factor between 0.0 and 1.0
A value of 0 stays zero.
The easiest way is to multiply each of the R,G,B values by some constant - if the constant is >1 it will make it brighter, and if <1 it will be darker. If you're making it brighter then you must test each value to make sure it doesn't go over the maximum (usually 255).
Not only is this simpler than the translation from RGB to HSL and back again, but it more closely approximates what happens when you shine a different amount of light at a physical object.
Adjusting the brightness of an image is one of the easiest image processing operations that can be done. All that is involved is adding the desired change in brightness to each of the red, green and blue colour components.
it would go something like this:
Code to ensures that the new values of red, green and blue are within the valid range.
Map from RGB to HSL (Hue/saturation/luminance), keep the hue and saturation the same, and just modify the luminance and then do the backward mapping from HSL to RGB.
You can read more about the RGB to HSL and HSL to RGB transformations here.