1

What is the benchmark algorithm to change perceptive brightness of an RGB pixel. such as:

if I have RGB (120, 33, 213) then ( ... using ... (0.299*R + 0.587*G + 0.114*B) ....) i get 79.533 as perceptive brightness but I do not have a way to raise the brightness of the same pixel to 80 as there are many possible values for it.

I have searched for solution for a while but could not get it. There are some algorithms to calculate the brightness such as:

Formula to determine brightness of RGB color

But these algorithms are not reversible.

Also, I am not considering using HSL or HSV as a correct approach unless somebody can correct me?

Edit: using HSL color space I am able to control the brightness while preserving the color to a great extent but I am wondering if there is a better approach.

Thanks-

Community
  • 1
  • 1

1 Answers1

2

You don't need to reverse the luminance equation, you just have to figure out the ratio to your desired luminance.

From your example:

//target luminance = 80

srcR = 120
srcG = 33
srcB = 213
srcLum = 79.533

destLum = 80
ratio = (destLum / srcLum) = 1.0058717...

destR = (srcR * ratio) = 120.705
destG = (srcG * ratio) = 33.194
destB = (srcB * ratio) = 214.251

You'll have to decide how you want to round them to get int values, but that's the general idea. Going from 79.5 to 80 isn't much of a change, though, so you won't see much. If you were going to 40, you'd end up with RGB(60,17,107).

As Mark Ransom points out below, once one of your values hits 255, you'll have to make a choice. To increase the luminance past that point, you'll either be changing the hue or the saturation(or both). His answer here shows the difference between the two quite well.

Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • This will work great until one of the RGB values goes above 255, then you need another strategy. You might get some help from [this answer](http://stackoverflow.com/a/141943/5987) but it will need tweaking for the different weighting involved. – Mark Ransom Jul 26 '13 at 18:51
  • Good point, either the hue or saturation has to change at that point. Edited. – Geobits Jul 26 '13 at 19:02
  • I have tried that as well but unfortunately RGB work very oddly when you work with the ratios. While this works for brightness correctly but using the this method looses its color changing saturation or hue. I have discarded this option and have moved onto using RGB to HSL translation using the following algorithm and it works pretty neatly: 1 - Translate RGB -> HSL 2 - Change L to the desired value 3 - Translate HSL -> RGB – mathsRuinedme Sep 03 '13 at 20:48
  • Though this process appears slow but custom implementation of RGB to HSL gave me an idea about how to extract pure colors.hue from RGB and it works great. For those who are interested: "In RGB colors, for every pair of 2 colors (e.g. RG, RB, GB) while 3rd being "0", if we fix value for one color to 255 and change the value of other by "C*255/60" (where C changes from 1 to 60) we get a pure color or pure hue". – mathsRuinedme Sep 03 '13 at 20:52