Formula to increase brightness of RGB?
Asked Answered
A

1

10

Quick question!

I have an R G B value and I want to convert to convert it to be 50% brighter. I found a gamma formula but I'm unsure if gamma is the correct way to go.

So far, I'm using:

        r = 255*((R/255.0)^ (1/1.5));
        g = 255*((G/255.0)^ (1/1.5));
        b = 255*((B/255.0)^ (1/1.5));

All I'm doing is multiplying the gamma by 1.5. The image does look brighter, but I'm unsure if its actually 50% brighter or if the formula I'm using is wrong. Is this correct?

Ararat answered 19/6, 2018 at 22:4 Comment(2)
Changing gamma will make things look brighter by changing the brightness of the mid tones. However it won't have as much effect on the colors near black or white. It does not change brightness by a consistent amount. See https://mcmap.net/q/21354/-programmatically-lighten-a-color/5987 for a different approach.Crossopterygian
Do you want to increase the apparent brightness (just multiply the by 1.5 for 50% increase). You could use gamma, if you want to add 50% more light (which do no appear as 50% brighter). This last method is what you should do for 3D or merging images (which requires real light). But for appearance, a simple multiplication is required.Actinolite
B
4

Literally "make it 50% brighter" is this

r = min(255, r*1.5)
g = min(255, g*1.5)
b = min(255, b*1.5)

You can also transform RGB to HSV map, increase the V [value] and reconvert it again to RGB.

Britishism answered 19/6, 2018 at 22:8 Comment(7)
My color is pink. (255,175,175). I used that formula and i got rgb value of (255,255,255) which is white.Ararat
I would say that it's right. What color do you expect? You have to deal with color spaces which are tricky. At the end the definition of color is also ambiguous. For instance we can take a specific value of wavelength of light to define a color. But we cannot multiply it by any number to get a "lighter" or "darker" colorBritishism
pink is already a lot bright, so so or you maintain the hue (at maximum brightness) or you try to estimate the brightness (but so you will have white)Actinolite
Convertig to HSV and increasing the V is the right way to go for the usual interpretation of "brightness". Just multiplying the numbers as above is usually not what you expect. For example blue (0,0,255) will never turn into a light blue with this method.Dardar
I have to point out that blue (0, 0, 255) converted to HSV is (240, 100, 100). That 100 for V is 100%. That's the max value. So you can't just increase the V in this case, either. You either have to change the H to get a slightly different "blue" that's perceived as "brighter", or you have to lower the S to get a "lighter" blue that's perceived as "brighter".Anastomose
@Anastomose Thanks, good point, but the key issue here is terminology: what exactly do we mean by "brighter"? In the HSV color space brightness is explicitly defined by the V (value) dimension (sometimes referred to as "brightness"), so #0000ff already represents the maximum brightness, as you mention. If by "brighter" you mean a color closer to white, then HSL might be a better choice, as its L dimension stands for lightness. But seems like "make it brighter" and "make it lighter" are 2 different tasksBritishism
@Britishism My apologies. I should have specifically thrown an @ user74696c in there because that reply was to them. Their example solution would have resulted in the exact same outcome. And yes, they're annoying issues that you can find plenty of research papers on. I know I'm hip deep in them and other google hits right now (how I wound up here!)Anastomose

© 2022 - 2024 — McMap. All rights reserved.