Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Layer Mode: Addition equation is working differently to official guide
#1
Hi, I'm a newbie and using GIMP(2.10.36) on Mac for several months. I have a question about Layer Mode: Addition.

According to the official guide, the Addition equation is "The pixel values of the upper and lower layers are added to each other. The resulting image is usually lighter."

So I made my own example to make sure this equation.

[Image: 2024-03-07_04-25-30-7bd241c35c31532650ca...0238e7.png]

[Image: 2024-03-07_04-25-30-446547fafc72833db53c...d39bdc.jpg]
1. Top Layer(RGB Red): 227.0 
2. Bottom Layer(RGB Red): 53.0
3. Resulting Image(RGB Red): 232.0

As far as I know, the Addition equation would be "E = min((M + I), 255)". According to the equation, "E = min((227.0  + 53.0), 255)" should yield 255. However, I got 232.0 as a result. Why does it happen?


Attached Files
.xcf   layer_mode-lighten-05-addition_color_examples-02(en).xcf (Size: 98.8 KB / Downloads: 58)
Reply
#2
No, because Gimp 2.10 is working in "Linear light". 

The 0 .. 255 values are gamma-corrected. In other words,they don't represent directly the amount  of light in the color channel, but some encoding which is convenient to pack as much as possible of the visual range in 255 values, taking in consideration that our eyes are more sensitives to differences in low values.

If you image is in some high precision linear mode, you can check the linear value with the Pixel representation in the Pointer and Sample points dialog

In theory this would mean:

Linear = ( RGB255 / 255 ) ^ 2.2

and

RGB255 = 255 * ( Linear ^ ( 1 / 2.2 ) )

In practice the conversion is done using the image color profile but if the color profile is sRGB (which is the case most of the time), the formulas above give a good approximation.

For instance your top color:

   

So Addition mode  is really "Convert to Linear, add the values, convert back to RGB255", and using the formulas you are not so far off:

   
   


Note that you can ask Gimp to work directly with the RGB255 values, by using the "Legacy" layer modes:

   

In which case the result is probably what you expect:

   

However, if this makes mathematical sense, this has no relation to the physical reality.
Reply
#3
(03-07-2024, 08:50 AM)Ofnuts Wrote: No, because Gimp 2.10 is working in "Linear light". 

The 0 .. 255 values are gamma-corrected. In other words,they don't represent directly the amount  of light in the color channel, but some encoding which is convenient to pack as much as possible of the visual range in 255 values, taking in consideration that our eyes are more sensitives to differences in low values.

If you image is in some high precision linear mode, you can check the linear value with the Pixel representation in the Pointer and Sample points dialog

In theory this would mean:

Linear = ( RGB255 / 255 ) ^ 2.2

and

RGB255 = 255 * ( Linear ^ ( 1 / 2.2 ) )

In practice the conversion is done using the image color profile but if the color profile is sRGB (which is the case most of the time), the formulas above give a good approximation.

For instance your top color:



So Addition mode  is really "Convert to Linear, add the values, convert back to RGB255", and using the formulas you are not so far off:





Note that you can ask Gimp to work directly with the RGB255 values, by using the "Legacy" layer modes:



In which case the result is probably what you expect:



However, if this makes mathematical sense, this has no relation to the physical reality.

Thanks a lot, Ofnuts. Now I realize why the official guide says "pixel value". May I ask another question? I'd like to learn more about the concept of "Linear light". Would you recommend any reference or documentation? I did several Google searches but I didn't get any good answer. Thanks in advance!
Reply
#4
It's not "linear light" which is a concept, it is "gamma correction". Linear light is just the ratio of the channel value to the maximum possible value (perfect diffused reflection) and is really what you see. Quick experiment:
  • In the image below:
    • The NW corner is 50% black pixels 50% white pixels (picked at random)
    • The SE corner is a dense checker board with also by design 50% black pixels 50% white pixels
    • The NE corner is a uniform #7F7F7F (half-range in gamma corrected values)
    • The SW corner is a uniform #BCBCBC (half-range in linear values)(in the Pointer dialog, you will see that its Pixel value is very close to 0.5
   
  • Open the image in a new tab (to make sure it is not scaled(*)...), or download and open in an image viewer
  • Stand back sufficiently far to not make out the pixels or even the "grain" in the NW corner
  • Note
    • Despite different implementation, the two 50/50 corners look the same because they roughly emit the same light
    • The NE corner is much darker,
    • The SW corner is about the same  as the NW and SE ones (if your display is well setup, they could be identical)
Also, if you use Filter > Bur > Pixelize on the NW/SE corners to average them out, you will find that their average color is #BCBCBC.... and the pixelization doesn't change the image much:
   
If you try the same thing on Gimp 2.8 (that works directly on the gamma-corrected value) that same filter yields a #7F7F7F and the pixellized areas are much darker:
   

(*) Because scaling directly on the gamma values (as done by many apps when doing thumbnails/previews) introduces the same kind of erroneous behavior as Gimp 2.8 Pixellize
Reply


Forum Jump: