Re: [Gimp-user] Layer addition - bug, feature, or user misunderstanding?

The problem is that a layer's opacity doesn't add -- it multiplies, like this:

Result = (opacity) * (this layer) + (100%-opacity) * (result of layers below)

This formula holds true regardless of the layer's assigned blending mode (and it's recursive, with the 
"result of layers below" defined by inserting the next layer down into the same formula).

So, if you want multiple translucent layers to have specific 'overall' contributions to the final image you 
need to work out the opacities for each individual layer, namely with lower layers having more opacity to 
compensate for their lower position in the stack.

Here is what happens with your example on the left -- Red layer has opacity 22.2%, Green has opacity 71.7%, 
Blue has opacity 6.1% (all this on top of a solid black background), so the overall image is blended like 

Image = 22.2% * (red) + (100%-22.2%) * (green,blue)
= 22.2% * (red) + 77.8% * (71.7% * green + (100%-71.7%) * (6.1% * blue) )
= 22.2% * (red) + 77.8% * (71.7% * green + 28.3% * (6.1% * blue) )
= 22.2% * (red) + 55.8% * (green) + 1.3% * (blue) 

And since we know that your red, green, and blue are all white, this means the overall image is:

= (22.2% + 55.8% + 1.3%) * (white)
= 79.3% white

Doesn't that 79% look rather familiar? :)  

Aside - the left half of your image is totally reproducible on GIMP 2.8 .  (I can't seem to reproduce the 
right half in 2.8, but I haven't examined the actual XCF either, so I don't have all the details.)

Now to fix the values ... first, Red is on top so it can keep the 22.2%; this leaves a translucency of 77.8% 
for everything below it.
For Green, below Red, divide its opacity by Red's translucency (above):  Green's opacity should be (71.7% / 
77.8%) = 92.1%.  This, in turn, leaves 7.9% of translucency for Blue below it.
For Blue (which is below both Green and Red), divide its opacity by the overall translucencies of both Red 
and Green.  You can do the math if you want (6.1% / 77.8% / 7.9%), but it conveniently works out to exactly 
100% opacity -- i.e. Blue doesn't need any translucency for itself because with both Red and Green on top of 
it (at the above opacities) only 6.1% of Blue will be visible anyway.

To prove it, just plug the new opacities back into the above formula:

Image = 22.2% * (red) + 77.8% * (92.1% * (green) + (100% - 92.1%) * (100% * blue) )
= 22.2% * (red) + 77.8% * (92.1% * (green) + 7.9% * (blue) )
= 22.2% * red + 71.7% * green + 6.1% * blue

PS - Keep in mind the above math only works when all three of your R/G/B layers are visible; if you toggle 
even one of them off the opacity of the ones underneath it will look off because they depended on the 
layer(s) above them to blend correctly.

-- Stratadrake
strata_ranger hotmail com
Numbers may not lie, but neither do they tell the whole truth.

From: ellestone ninedegreesbelow com
To: gimp-user-list gnome org
Date: Mon, 12 Oct 2015 11:22:46 -0400
Subject: [Gimp-user] Layer addition - bug, feature, or user misunderstanding?

Using GIMP 2.9 updated yesterday, two different ways of adding layers 
produce different results. But it seems to me that the two ways should 
produce the same results. Here is a screenshot:,

Are the different results a bug, a feature, or am I making an obvious 
mistake or just not understanding something?

Looking at the screenshot, the "channel" layers were produced by making 
a solid white layer and dragging the Red, Blue, and Green channels over 
to the layer stack. So of course each channel layer also has R=G=B=1.0.

The channel layers are added using layer percent opacities of 22.2 for 
the Red channel layer, 71.7% opacity for the Green channel layer, and 
6.1% opacity for the Blue channel layer. The percentages are the correct 
percentages for producing a Luminance conversion to black and white by 
adding the Red, Green, and Blue channels together as layers.

The result of adding the three layers should be white, R=G=B=1.0, which 
is what happens with the second way of adding the layers. But the first 
way, using the more obvious "add each layer to the layers below", 
produces R=G=B=0.793257.

Here's a download link for the actual XCF file: 

You'll need to reset *all* of the layer opacities to the values given 
above, because for some reason saving to disk and reopening causes layer 
opacities to shift slightly (for example, the Blue layer opacities shift 
to 5.9% instead of staying at 6.1%).

The image is an sRGB image and the precision is 32-bit floating point 
(linear) in order to get the layers to properly add up to R=G=B=1.0, 
which they should anyway for solid white, but results would be wrong for 
colors other than solid white or solid black.

Elle, puzzled
Color management and free/libre photography
gimp-user-list mailing list
List address:    gimp-user-list gnome org
List membership:
List archives:

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]