It is currently Thu May 02, 2024 4:15 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 5:19 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
GIMP Version: 2.8.4
Operating System: Windows
OS Version: Win 7 32 bits
GIMP Experience: Beginner Level



To all Gimp experts chatting here.
I would like to understand a little bit the arithmetic behind the Gimp layer mode.
This morning I had a kind of surprise playing with Gimp layer modes in this context:
1 - create a new image transparent
2 - add a new layer on top transparent
3 - drawing/painting/filling with a picture the top layer
Quite obviously the image was displaying the top layer.
At this point I wanted to play by changing the "normal" with each of the other available modes, and - big surprise for me - ONLY with normal or dissolve I was seeing the picture, in ALL other modes I saw a transparent image (even with: multiply, overlay, etc.).
Because it looked very strange for my (limited) understanding of arithmetic, I made a try with another photo editor, Paint Shop Pro and results are completely different, in the sense that with EACH mode I was seeing the image, except for dodge which gave a black screen and burn which gave a white screen.
Well, I know that each photo editor implements a different arithmetic on layer modes, but - let me say - at least if "something" is added or overlaid to "nothing" then "something" should appear!
Could somebody of you experts tell me something about this behaviour of our friend Gimp?
Many thanks!!!

_________________
"Where am I ?"


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: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 5:29 am  (#2) 
Offline
Global Moderator
User avatar

Joined: Apr 07, 2010
Posts: 14182
I didn't think layer modes worked with a transparent below the dupe. The layer mode has nothing below it to subtract or add from.

_________________
Image


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 5:45 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Molly, as I said above with a "normal" human arithmetic if you add "something" to "nothing" you SHOULD get "something"....

_________________
"Where am I ?"


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 5:57 am  (#4) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
A blend in maths terms isn't always an add though (e.g. multiply anything by zero and you will get zero), but it will depend mainly on how gimp treats the alpha layer during a blend - hopefully somebody can explain.


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 6:02 am  (#5) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2425
Is it not explained here?
http://docs.gimp.org/2.8/en/gimp-concep ... modes.html

eg.
Image

_________________
Image


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 6:09 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Well, if Gimp uses "multiply" to "overlay", then the result is understandable (x * 0 = 0); does Gimp use a multiply mechanism wherever, also when adding for instance?

_________________
"Where am I ?"


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 6:21 am  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
dinasset wrote:
Molly, as I said above with a "normal" human arithmetic if you add "something" to "nothing" you SHOULD get "something"....

"Nothing" is (0,0,0) and is black :)

"Normal" mode (and dissolve) replace the alpha channel of the stack of layers below them. But in other modes, the arithmetic is performed on the RGB channels but the transparency of the layer stack below the "mode'd" channel is retained, so if the layer is transparent, there is nothing to see.

_________________
Image


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 6:26 am  (#8) 
Offline
GimpChat Member

Joined: Sep 24, 2012
Posts: 275
Location: Scotland
ofnuts wrote:
dinasset wrote:
Molly, as I said above with a "normal" human arithmetic if you add "something" to "nothing" you SHOULD get "something"....

"Nothing" is (0,0,0) and is black :)

"Normal" mode (and dissolve) replace the alpha channel of the stack of layers below them. But in other modes, the arithmetic is performed on the RGB channels but the transparency of the layer stack below the "mode'd" channel is retained, so if the layer is transparent, there is nothing to see.


Aha that explains it then :)


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 6:48 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
ofnuts is perfectly right.
Actually, most of the documentation available on the web to describe formulas of blending modes are missing this important point : what to do with the alpha-channels of each layer and how to compute the alpha-channel of the resulting (blended) image.


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 7:36 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
Ronounours wrote:
ofnuts is perfectly right.
Actually, most of the documentation available on the web to describe formulas of blending modes are missing this important point : what to do with the alpha-channels of each layer and how to compute the alpha-channel of the resulting (blended) image.


What I have not quite figured out yet is how the blend mode formula (that assumes full opacity) is adapted when the mod'ed layer is partially transparent. Everyone knows that playing with the opacity slider for that layer tunes the amount of the blend mode effect...

_________________
Image


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 7:47 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
based on the given info I removed the alpha channel from the top layer and results are ALL completely different!
Thanks to ofnuts and all other experts here (a poor gimp-er needs a sort of a master in gimp-science to understand this behaviour ... well this is the reason why gimp-chat exist!...

_________________
"Where am I ?"


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 8:28 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
ofnuts wrote:
What I have not quite figured out yet is how the blend mode formula (that assumes full opacity) is adapted when the mod'ed layer is partially transparent. Everyone knows that playing with the opacity slider for that layer tunes the amount of the blend mode effect...


From what I understood (and implemented), in this case the blending operation is actually decomposed into two steps :
- First, the computation of the blended image, according to the selected mode (assuming full opacity).
- Second, the computation of the alpha blending between the base layer and the blended layer. And in that case, it is well known how to get the resulting alpha-channel, when the two layers to composite have alpha-channels too (accrding to http://en.wikipedia.org/wiki/Alpha_compositing).


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Tue Feb 26, 2013 9:43 am  (#13) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
Ronounours wrote:
ofnuts wrote:
What I have not quite figured out yet is how the blend mode formula (that assumes full opacity) is adapted when the mod'ed layer is partially transparent. Everyone knows that playing with the opacity slider for that layer tunes the amount of the blend mode effect...


From what I understood (and implemented), in this case the blending operation is actually decomposed into two steps :
- First, the computation of the blended image, according to the selected mode (assuming full opacity).
- Second, the computation of the alpha blending between the base layer and the blended layer. And in that case, it is well known how to get the resulting alpha-channel, when the two layers to composite have alpha-channels too (accrding to http://en.wikipedia.org/wiki/Alpha_compositing).

I still don't get it. AFAIK in normal mode a layer is composited with the image resulting of the compositing of the stack below it. So if you have, bottom to top, A,B,C,D: A is composed with B:
RGBA(AB) = AlphaCompose(RGBA(A),RGBA(B))

then AB with C:
RGBA(ABC) = AlphaCompose(RGA(AB),RGBA(C))

No mystery here. I assume that the actual opacity of a pixel is the product of the alpha value of the pixels and the general opacity of the layer (as set on the Opacity slider).

So if we add a layer M in one of the blend modes, assuming full opacity of M we have:
RGB(ABCM) = Blend(RGB(ABC),RGB(M))
Alpha(ABCM) = Alpha(ABC)
where Blend() is one of the formulas, and there is no compositing... so what happens when A(M) isn't 100%? Is there, at least conceptually:
# compute RGB image assuming full opacity, as above
RGB(ABCM) = Blend(RGB(ABC),RGB(M))
# Compute alpha channel for that image
A(ABCM) = A(M)*A(ABC)
# Compute final by composing original with blended image
RGBA(Final)= AlphaCompose(RGBA(ABC),RGBA(ABCM))

How far off am I?

_________________
Image


Top
 Post subject: Re: gimp layer mode arithmetic
PostPosted: Fri Mar 08, 2013 7:00 pm  (#14) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
5.6 The Blending Modes info at Grokking the Gimp is always worth a look.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) layer mode preview stopped working

3

No new posts PARTIALLY SOLVED How does it work on layer blendng mode "Normal"

1

No new posts Attachment(s) Default vs. Legacy: "Subtract" Layer Mode: Different results

8

No new posts Attachment(s) How does it works on Layer Blending Mode "Add" with Alpha Channel?

4

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

7



* Login  



Powered by phpBB3 © phpBB Group