• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

what is the mathmatical formula of Gradient map

New Here ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

I am a newbie of photoshop and the effects of gradient map confuse me. 

I thought gradient map has consistent formula for the 3 color channel(RGB), but it doesn't. 

I set left side of gradient map to black(0, 0, 0), and right side to white(255,255, 255), and the gradient map layer changes rgb color of below layer as following: 

(255, 0, 0) -> (66, 66, 66) 

(0, 255, 0) -> (156, 156, 156) 

(0, 0, 255) -> (18, 18, 18) 

such result is really beyond my understanding, So why do I get this effect?

Views

3.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , May 29, 2019 May 29, 2019

Again my test gradient (255R 0G 0B) --> (255R 255G 255B), that is Red --> White:

The graphic shows the values for R,G,B in the range 0...255 over the distance x=0...1000 pixels,

extracted by a PostScript program from the CS6 file.

gradient-2.png

One can see that the values are essentially linear, but with increased contrast over the distance,

an S-curve). There is no extra Gamma-encoding and no CIELab-encoding involved.

The contrast gain IMHO doesn't make any sense: The dark end ist too dark and the light end is

too

...

Votes

Translate

Translate
Adobe
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Hi

Gradient map uses the Lightness value (see Lab values in the colour picker) and maps those onto your gradient.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Two things are happening here. First, a B/W gradient is obviously monochrome, so all R=G=B.

But then something interesting happens. These calculations are done in the luminance component of the data, ignoring the color component. When you dive deep into the heart of Photoshop's engine room, things operate in Lab color mode (or something very similar, but let's just say Lab for now).

And in Lab, separating luminance and color components, the inherent lightness of any color is accounted for. It's easier to illustrate than to describe:

desaturation.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

For me the explanations are not convincing, so far.

Let's have a look at a gradient test image, made by Photoshop CS6 in sRGB:

Gradient-1.png

1. The distance x=0.0 to 1.0 is divided linearly.

2.  R is constant, G and B are not linear.

3.  L is not linear

4. G and B are not linear with gamma encoding taken into account (center is at 127/128)

5. The gradient is visually far from being perfect: we have almost equal lightnesses in the three

     columns at the red end.

I don't know the mathematical function. There are many possibilities, linear in R, G, B or linear

in R', G', B' ( Gamma encoded) or linear in L of Lab*) or linear in Lab, or linear in HSB (HSL,HLS)

or last but not least linear in XYZ, which would be physically reasonable.

where linear means a straight line in the respective color space with equidistant interpolation.

*) Choosing colors sorted by L instead of linearly interpolating in Lab is for me not understandable.

Not all gradients have the same hue or its equivalent in Lab, the same ratio a:b.

Or my test is wrong...

Best regards --Gernot Hoffmann

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Hi Gernot

Your test was interesting and got me to do some more thinking.

The original posters question led from unexpected results when converting three colours to a gradient map adjustment layer set black to white. So I also looked at the L values (I used sRGB for testing)


The Red 255,0,0 L63   mapped to 66,66,66  L27
The Green 0,255,0  L83 mapped to 156,156,156 L65
The Blue 0,0,255 L30 mapped to 18,18,18   L3

So my next test was to create a black and white gradient using a Gradient Fill layer. Put a gradient map adjustment layer above it mapping to the same black to white range.  I expected this to be either one to one mapping of the L values or something that would explain the mapping above. I got neither.

Instead I got a distinct S curve ( some sample values shown below)

L0 mapped to L0

L25 mapped to L19
L50 mapped to L50

L75 mapped to L79

L100 mapped to L100

I tried the same in a linear gamma and got similar results.

So far I've not been able to work out an exact mapping that fits the black to white gradient and the 3 colours above.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

For as long as I've been visiting these forums, people have been trying to figure out what this elusive and mysterious "Luminosity" really is. It is very similar to Lab L, and it behaves the same way - but it's not exactly the same. It's always a few numbers off one way or the other.

I've started to suspect that it just is what it is - a custom variety not found anywhere else and not directly corresponding to any standard. It was just used by the original PS engineers because it did the job. It worked the way they needed it to.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

Again my test gradient (255R 0G 0B) --> (255R 255G 255B), that is Red --> White:

The graphic shows the values for R,G,B in the range 0...255 over the distance x=0...1000 pixels,

extracted by a PostScript program from the CS6 file.

gradient-2.png

One can see that the values are essentially linear, but with increased contrast over the distance,

an S-curve). There is no extra Gamma-encoding and no CIELab-encoding involved.

The contrast gain IMHO doesn't make any sense: The dark end ist too dark and the light end is

too light.

Best regards --Gernot Hoffmann

P.S.: at present, Photoshop cannot read this PostScript file, whereas my PostScript editor can

interprete it. Therefore I can show only this screenshot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 30, 2019 May 30, 2019

Copy link to clipboard

Copied

Here we have the mathematical functions for Photoshop's gradient and an arbitray example:

gradientmath.png

Thick pale lines are graphs of the mathematical functions.

Thin steplines are values of the actual content, normalized for the range 0...1 .

gradient-5.png

Gernot Hoffmann

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

So far it could be clarified how Photoshop constructs a  gradient in RGB:

not linear over the x-coordinate, but almost linear with an enlarged contrast by a polynomial

S-curve.

It's funny that the function y(x) ) = y0+ (y1 - y0) (x - k g(x) ) uses just k=1, which doesn't have

any psychophysical meaning.

The next question – the original question – is, how Photoshop might execute a Gradient Map.

For a Gradient Map one needs a source Image A and a gradient, visualized by an Image B.

Result is the Image C.

So far, according Photoshop's help texts, it's clear, the dark parts of A get the color of the

gradient's left end and bright parts that of the gradients right end. What happens between?

From post #1 (Dave) I read the assumption, that the values between are interpolated by

using the L-scale of CIELab. The following test should prove or disprove this assumption.

Image A is a manually made step wedge in Lab, obviously linear (therefore a gradient could

not be used).

Image B is an arbitrary gradient. RGB (0 200 50) --> (255 50 200)

Image C should reproduce image B in steps of image A.

ThreeBars.png

The ends are as expected, but the interpolation doesn't seem to be accurate.

In order to compare this visually, Image B is copied into image C. Note that for this comparison

everything was merged and converted to sRGB.

FourBars.png

Now we can see, that the interpolation doesn't happen according to the assumption.

The function is not L of Lab but perhaps the mysterious luminosity...

Considering all these complex transforms, there might be mistakes (my mistakes).

I'm open for any discussion. On the other hand I understand that re-engineering Photoshop

algorithms isn't really pleasing.

Gernot Hoffmann

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

Hi Gernot

I agree , as I posted in post 4 - the mapping is related to luminosity in a loose sense (i.e. darkness and brightness)  but is not a straightforward L mapping as a grey pixel with an L value gets mapped differently to a coloured pixel with the same L value.
So still a mystery.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

I had written the last correction for my contribution at 18:40 local time.

Now it's 20:35 and my stuff is still not public. Who's responsible for this

delay?

Gernot Hoffmann

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Interestingly if you have three areas of pure primary RGB values (255 for each) and then run DeSaturate on them. You'll get the same appearance as you do with a Black to White Gradient Map. EXCEPT for Adobe RGB (1998). That gives a very different result in the reds especially.

I suspect it has something to do with the mean averaging of the hue value relative to the size of the gamut you're calculating the average for. a 50% mean average in one gamut will not be the same, relative to coordinates/position in the gamut for Adobe RGB as it is for ProPhoto RGB.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

LATEST

Thanks all you guys!

I recently learn a lot about color model, and get to know that Photoshop use HCY(hue, chroma, luminance) color model in many cases.

For the gradient map, I have known the approximate formula.

let luminance Y = (R/255)*0.30 + (G/255)*0.59 + (B/255)*0.11, then just use Y to choose the color in map.

R(converted) = (1-Y)*R(leftside of map) + Y*R(right side of map)

G(converted) = (1-Y)*G(leftside of map) + Y*G(right side of map)

B(converted) = (1-Y)*B(leftside of map) + Y*B(right side of map)

For Y=50%, the above formula is accurate;

For Y<50%, the calculated result is a little smaller than actual value;

For Y>50%, the calculated result is a little greater than actual value.

Also, I wrote a CEP extension to show HCY color value:

GitHub - XiaoXiaoLui/photoshop_hsl_plugin: CEP extension for showing HCY or HSL color in photoshop

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines