It is currently Mon Jul 08, 2024 9:44 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: arrange layer transparancies so they contribute equally to final
PostPosted: Fri Jun 07, 2013 4:38 am  (#1) 
Offline
GimpChat Member

Joined: Oct 31, 2011
Posts: 112
GIMP Version: 2.6.11
Operating System: Windows
OS Version: XP - SP3
GIMP Experience: Beginner Level



Hey guys,

I have a stupid question. If I have several layers, and I want all of them to contribute equally to the final image, then how should I arrange their transparancies? Is it correct like this:

If I have two layers, then the topmost layer should be 50%, and the bottom should be 100%
If I have three layers, than the top should be 33%, middle 67%, bottom 100%
If I have four layers, than the top to bottom should be: 25%, 50%, 75%, 100%.

Is that correct? I am asking in relation with this tutorial: http://diangos.deviantart.com/art/High- ... -298317377

If that is correct, then try this one: create 3 layers, fill the first with pure red, second with pure green, and third with pure blue. Change the transparancies into 33%, 67%, and 100%. why the final result is not white? also, the final color changes slightly based on the arrangement of the colors.

I hope GIMP scientists could help me. Thanx :D

Edit:

Btw after I think about it, maybe the transparencies arrangement is indeed wrong. I calculate it as the following (beware a lot of maths!). If you have two layers, the top layer has color a and transparency x, the bottom layer has transparency 1 (transparency 1 means 100% in GIMP notation) and color b, then the final color is:

a.x + (1-x).b

is that correct? and if you want both layer contributes equally, then x must be equal to 1-x, which means x = 0.5 (means 50% in GIMP convention).

But suppose we have 3 layers. the color of each layer, from top to bottom, is a,b,c; and their transparencies are x,y,1 (the bottom layer has 100% transparency). The middle and bottom layer combined, will have color:

b.y + (1-y).c

then combined with the top layer, the final color is:

a.x + (1-x).[b.y + (1-y).c] = a.x + b.y.(1-x) + c.(1-x).(1-y)

so if you want all 3 layers contribute equally, then we must have:

x = y.(1-x)
y.(1-x) = (1-x).(1-y)
x = (1-x).(1-y)

Solving those three equations, I get x = 1/3, y = 1/2. So it is NOT x = 1/3 (33%) and y = 2/3 (67%) like I claimed before. Instead, if I use x = 1/3 and y = 2/3, the final color will be (1/3).a + (4/9).b+(2/9).c. It means that all three layers don't contribute equally, but the middle contributes most. Is this correct guys?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Fri Jun 07, 2013 6:40 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Mar 23, 2012
Posts: 7316
Location: Göteborg at last!
I would imagine that 1=100, 2=50, 3=25 etc. I'm not a great mathematician but it makes sense to me.


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Fri Jun 07, 2013 9:14 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
Please define mathematically the "contribute equally to the final image"... :)

Not a great mathematician either, but I learned to be wary of common sense with maths :)

With three layers (bottom one being opaque), let's start by combining the top two layers into a virtual layer that has a color C and an alpha α: over the bottom layer with color B and alpha=1 this gives:

(0) Final=C α + B(1-α)

So we want the top two layers to have a combined alpha of 67% and equal colors... So for these two layers (t)op and(b)ottom:

Their combined (A)lpha:
(1) α=αt+αb-αtαb=2/3
Their (C)olor:
(2) C=Ctαt+Cbαb(1-At)

For equal contribution, the weights of each layer color in the Color formula must be equal so:
(3a) αt=αb(1-αt) or:
(3b) αb=αt/(1-αt)

If you put this back in (1) to express it only with αt:
(4) αt+αt/(1-αt)-αtαt/(1-αt)=2/3

After some simplifications:
(5) 2αt(1-αt)/(1-αt)=2/3

Since αt!=1:
(6) 2αt=2/3 => αt=1/3

So using (3b)
(7) αb=1/2

Experiment: see attached image, which gives a nice uniform gray 33%:

Attachment:
Composite-thirds.xcf [3.9 KiB]
Downloaded 101 times

_________________
Image


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Fri Jun 07, 2013 10:12 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
PS: in light of the above actually you can do it using good common sense and a bit of recursion:

Blending from bottom:

- Bottom layer is 100%
- Next layer should be 50% (result is 100% opaque), to produce a virtual bottom layer with equal contributions
- A third layer should have a contribution of 1/3... so an alpha of 33%...
- A fourth layer should be 25%
- In other words layer N should have an opacity of 1/N.

_________________
Image


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 11:07 am  (#5) 
Offline
GimpChat Member

Joined: Oct 31, 2011
Posts: 112
Erisian wrote:
I would imagine that 1=100, 2=50, 3=25 etc. I'm not a great mathematician but it makes sense to me.


Hey Erisian,

The correct answer is like what ofnuts said in post no.4. If you have n layers, then the top layer is 1/n, the one below it is 1/(n-1), and so on, until the bottom layer is 1.


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 11:12 am  (#6) 
Offline
GimpChat Member

Joined: Oct 31, 2011
Posts: 112
ofnuts wrote:
PS: in light of the above actually you can do it using good common sense and a bit of recursion:

Blending from bottom:

- Bottom layer is 100%
- Next layer should be 50% (result is 100% opaque), to produce a virtual bottom layer with equal contributions
- A third layer should have a contribution of 1/3... so an alpha of 33%...
- A fourth layer should be 25%
- In other words layer N should have an opacity of 1/N.


Hey ofnuts,

Sorry I don't really follow your calculation in post no.3, but from my calculation, I also get the same result like yours in post no.4, so I guess we are doing the same thing :D

Indeed, if I arrange the red, green, blue layers in 33%, 50%, and 100%, the final result is gray and independent to the color arrangement (whether the top layer is red or blue, etc). But if I arrange it 33%, 67%, 100% then the 2nd layer contributes most, so the final color has the slight tint of whatever color of 2nd layer.

Btw do you know why the result is not white? Red, green, blue in equal amount should produce white no?


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 11:26 am  (#7) 
Offline
Script Coder

Joined: Apr 10, 2011
Posts: 532
This question can be answered with MATH!

Two layers are composited together so that the first layer's colour is added in, then the second layer is mixed in by taking a weighted average of the first and second layer, where the weighting is based on the transparency of the second layer.

It gets more complicated if the first layer is also transparent, so for the sake of simplicity, let's just assume that the first layer is fully opaque. For the sake of simplicity, let's also consider grayscale colours.

So, for example, first layer is black (0) and second layer is white (255). The resulting composition is the weighted average of the two. So for example:

- Second layer is 100% opaque: result = (0 * 0) + (255 * 1) = 255
- Second layer is 50% opaque: result = (0 * 0.5) + (255 * 0.5) = 127.5 (rounded up to 128)
- Second layer is 25% opaque: result = (0 * 0.75) + (255 * 0.25) = 63.75 (rounded up to 64)

If you have more than one layer, it's just calculated in pairs of two layers: first, the first two layers are composited, the result of that composition is composited with the third layer, and so on.

So if we have eg. 3 layers, where first is 0, the second is 100, the third is 200, then by mixing them in equal amounts the result should be 100.

0 * 0.5 + 100 * 0.5 = 50
50 * 2/3 + 200 * 1/3 = 100

Math solves all problems.


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 4:33 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
hanciong wrote:
ofnuts wrote:
PS: in light of the above actually you can do it using good common sense and a bit of recursion:

Blending from bottom:

- Bottom layer is 100%
- Next layer should be 50% (result is 100% opaque), to produce a virtual bottom layer with equal contributions
- A third layer should have a contribution of 1/3... so an alpha of 33%...
- A fourth layer should be 25%
- In other words layer N should have an opacity of 1/N.


Hey ofnuts,

Sorry I don't really follow your calculation in post no.3, but from my calculation, I also get the same result like yours in post no.4, so I guess we are doing the same thing :D

Indeed, if I arrange the red, green, blue layers in 33%, 50%, and 100%, the final result is gray and independent to the color arrangement (whether the top layer is red or blue, etc). But if I arrange it 33%, 67%, 100% then the 2nd layer contributes most, so the final color has the slight tint of whatever color of 2nd layer.

Btw do you know why the result is not white? Red, green, blue in equal amount should produce white no?


100% red, 100% blue, and 100% green in equal mounts should indeed produce white. But since we take only 1/3 of the only image with red, we get 33% red, and same for green and blue. So you get 33% gray...

_________________
Image


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 4:35 pm  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
dd wrote:
This question can be answered with MATH!


Indeed... but your maths don't give the same result as ours?

_________________
Image


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 5:23 pm  (#10) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
I'm no math expert either but I do recall an interesting discussion in advanced calculus class of what is being described here as o=1/n, where n = # of layers.

Taking the graph of o=1/n and rotating it around a 3d axis, describes what is referred to as "Gabriel's Horn", which is an object thought to have infinite surface area, but finite volume. It was quite the paradox before the advent of modern calculus.

Anyway, it's not that relevant to this conversation but I thought it was an interesting aside.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Sun Jun 09, 2013 5:29 pm  (#11) 
Offline
Script Coder

Joined: Apr 10, 2011
Posts: 532
ofnuts wrote:
dd wrote:
This question can be answered with MATH!


Indeed... but your maths don't give the same result as ours?


Don't they? Why not?


Top
 Post subject: Re: arrange layer transparancies so they contribute equally to final
PostPosted: Mon Jun 10, 2013 4:46 am  (#12) 
Offline
GimpChat Member

Joined: Oct 31, 2011
Posts: 112
ofnuts wrote:

100% red, 100% blue, and 100% green in equal mounts should indeed produce white. But since we take only 1/3 of the only image with red, we get 33% red, and same for green and blue. So you get 33% gray...


aarrgghh ok then, I understand :D


Top
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) FPS (Free Paint Strokes) 2022 A - Final tests

46

No new posts Attachment(s) Adding a image as a layer, moving layer, and then flattening

2

No new posts Shortcuts to 2.10 documentation re: Layer & Layer-group modes

0

No new posts How do I script a new white layer to the bottom of the layer stack

7

No new posts Add layer mask hides the entire layer

3



* Login  



Powered by phpBB3 © phpBB Group