What is the formula for increasing the brightness of an image in the same way as the L component does in Photoshop?

For example, I have a pixel with these values:

CGFloat red = 34 // 0 - 255 CGFloat green = 128 CGFloat blue = 190 

and I want to increase the brightness so that the blue is 255. NOTE: With "Brilliance," I mean the Photoshop L component in the LAB color space. See photos!

There must be a special formula for calculating RGB values ​​for increased brightness, since RGB values ​​change non-linearly!

Evidence. I did a test in Photoshop and created the same color, and then opened the color picker to examine it:

Original color

Then I activated the L component of the LAB color space, which controls the brightness (at least this is what I'm talking about - I mean the brightness controlled by this component L. Guess what it is brightness).

So, with L activated, I dragged the slider from the left up until B reached 255: Modified color

Now read the resulting RGB values:

 CGFloat newRed = 112 // 0 - 255 CGFloat newGreen = 188 CGFloat newBlue = 255 

The differences between them:

 newRed - red = +78 newGreen - green = +60 newBlue - blue = +65 

Interest:

 red shift: +38.42% green shift: +29.55% blue shift: +32.01% 

This does not match the well-known RGB Luminance calculation formula, which is close to luminance = (red * 0.3) + (green * 0.6) + (blue * 0.1) .

Obviously, they were shifted nonlinearly.

Is there a well-known way to calculate newRed, newGreen, newBlue from red, green, blue in the same way as Photoshop does it?

+4
source share
1 answer

So, do you want to convert RGB color to Lab color space? Of course it is possible.

But there are many different standards that all refer to the common name "Lab" color. You will need to choose the one that will be used when writing your algorithm. Photoshop specifically uses the CIELAB D50 standard, so you'll want to use it if you need to accurately simulate its processing.

Another thing you should keep in mind is that the RGB model is device-dependent , which means that to convert from RGB to Lab, you first need to convert from RGB to some device-independent absolute color space. Adobe does this with its Adobe RGB format, but you can use something standard like sRGB. The setup process takes into account the dependence of the RGB color on the device, but converts the color to one that is independent of the device. After that, you can take the last step of converting color to Lab color space.

The Wikipedia article contains some background information and useful formulas when writing a transformation algorithm. And here is someone who has already written such a conversion algorithm . And one for MATLAB , perhaps you can convert.

Depending on how serious you are (maybe not), you can also download the GIMP source and see if conversion algorithms are implemented. Their software claims to support laboratory space.

Be careful, however, when accessing RGB. Lab color space can represent colors that are outside the sRGB range. Even in Photoshop, most of what you see in Lab mode is discarded after converting the image to RGB (or CMYK).


Edit: It’s also worth considering that if your only goal is to lighten the color in the color space that better approximates the perception of human perception than RGB, you may not need to fuss with the Lab at all. Many applications do this by converting to the HSL or HSV color space . (Photoshop calls HSV, HSB).

The advantage is that you can simply adjust the Lightness or Value values ​​to change the color intensity (just as you would adjust the Luminance value in the Lab color space), but the conversion algorithms are much simpler (and often built-in to the standard libraries of your language of choice).

For example, see my answer to this question for a conversion algorithm written in .NET.

+4
source

All Articles