RSS/Atom feed Twitter
Site is read-only, email is disabled

how layers actually get merged?

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

5 of 5 messages available
Toggle history

Please log in to manage your subscriptions.

how layers actually get merged? bear 20 Sep 15:39
  how layers actually get merged? Simon Budig 20 Sep 15:48
how layers actually get merged? William Skaggs 20 Sep 16:29
  how layers actually get merged? Joao S. O. Bueno Calligaris 21 Sep 15:42
how layers actually get merged? bear 20 Sep 16:54
bear
2004-09-20 15:39:15 UTC (over 19 years ago)

how layers actually get merged?

hi,
Assume there are four layers, all of which are in Normal mode and grayscale. for a specific pixel in each layer,
Their intensity and alpha values(mapped to [0,1]) are i1,a1
i2,a2
i3,a3
i4(background)

the merged intensity is ((i1*a1+i2*(1-a1))*a2+i3*(1-a2))*a3+i4*(1-a3) am I correct? Thanks!

Simon Budig
2004-09-20 15:48:11 UTC (over 19 years ago)

how layers actually get merged?

bear (xgl99@mails.tsinghua.edu.cn) wrote:

Assume there are four layers, all of which are in Normal mode and grayscale. for a specific pixel in each layer,
Their intensity and alpha values(mapped to [0,1]) are i1,a1
i2,a2
i3,a3
i4(background)

the merged intensity is ((i1*a1+i2*(1-a1))*a2+i3*(1-a2))*a3+i4*(1-a3) am I correct? Thanks!

Yes. You might want to look for the paper T. Porter & T. Duff - Compositing Digital Images for an explantation and the reasoning behind these rules.

The paper itself is available at e.g. http://keithp.com/~keithp/porterduff/

Bye, Simon

William Skaggs
2004-09-20 16:29:44 UTC (over 19 years ago)

how layers actually get merged?

Bear wrote:

Assume there are four layers, all of which are in Normal mode and grayscale. for a specific pixel in each layer,
Their intensity and alpha values(mapped to [0,1]) are i1,a1
i2,a2
i3,a3
i4(background)

the merged intensity is ((i1*a1+i2*(1-a1))*a2+i3*(1-a2))*a3+i4*(1-a3) am I correct? Thanks!

I hope not. The proper expression should be

a1*i1 + (1-a1) * (a2*i2 + (1-a2) * (a3*i3 + (1-a3) * i4)).

That is, you have the expression reversed. With your expression, the background could show through even with opaque layers above it.

The best way to think about it is that the projection at layer n is given by the recursive formula

P(n) = a_n * i_n + (1 - a_n) * P(n-1),

where the background is layer 0, and P(0) = i_0.

Best, -- Bill


______________ ______________ ______________ ______________ Sent via the KillerWebMail system at primate.ucdavis.edu

bear
2004-09-20 16:54:16 UTC (over 19 years ago)

how layers actually get merged?

oh, I made a mistake. Thanks a lot!

In your mail:

From: "William Skaggs"
Reply-To:
To: ,

bear

Subject: Re: [Gimp-developer] how layers actually get merged?

Bear wrote:

Assume there are four layers, all of which are in Normal mode and grayscale. for a specific pixel in each layer,
Their intensity and alpha values(mapped to [0,1]) are i1,a1
i2,a2
i3,a3
i4(background)

the merged intensity is ((i1*a1+i2*(1-a1))*a2+i3*(1-a2))*a3+i4*(1-a3) am I correct? Thanks!

I hope not. The proper expression should be

a1*i1 + (1-a1) * (a2*i2 + (1-a2) * (a3*i3 + (1-a3) * i4)).

That is, you have the expression reversed. With your expression, the background could show through even with opaque layers above it.

Joao S. O. Bueno Calligaris
2004-09-21 15:42:18 UTC (over 19 years ago)

how layers actually get merged?

On Monday 20 September 2004 11:29, William Skaggs wrote:

Bear wrote:

Assume there are four layers, all of which are in Normal mode and grayscale. for a specific pixel in each layer, Their intensity and alpha values(mapped to [0,1]) are i1,a1
i2,a2
i3,a3
i4(background)

the merged intensity is ((i1*a1+i2*(1-a1))*a2+i3*(1-a2))*a3+i4*(1-a3) am I correct? Thanks!

I hope not. The proper expression should be

a1*i1 + (1-a1) * (a2*i2 + (1-a2) * (a3*i3 + (1-a3) * i4)).

Peering into the code, it is actually simpler than that. The GIMP always treat layers in groups of two, starting at the botton It would do:
new_i3 = i3 * a3 + i4 * (1 - a3)
then:
new_i2 = i2 * a2 + new_i3 * (1 - a2)

and so on. The finalr esult is like above - but it is easier to think on it 2 layers at a time.

That is, you have the expression reversed. With your expression, the background could show through even with opaque layers above it.

The best way to think about it is that the projection at layer n is given by the recursive formula

P(n) = a_n * i_n + (1 - a_n) * P(n-1),

where the background is layer 0, and P(0) = i_0.

Best, -- Bill