It is currently Wed Jul 24, 2024 8:22 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 5:55 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
Why would I need layer's alpha channel in gimp
when seemingly everything could be done with masks? Maybe I'm wrong?

What can be done in GIMP with alpha channel that cannot be done with masks?

Some thoughts on the dilemma.
There are obvious advantages in using layer masks over alpha channels:
you can refine the mask at any time, make complex selections by painting on masks, your image is still intact, etc.

Not the least importance is the gimp document size.
I created 2 images in gimp that look identical - one using alpha channel, the other - layer mask.

Image
Attachment:
gimp_M_vs_A.zip [1.33 MiB]
Downloaded 228 times


Alpha channel workflow
1.Open image
2.Add alpha channel
3.Use eraser tool or selection to make parts of the image transparent.

Masks workflow
1. Open image (do not add alpha channel)
2. Add Black (Full transparency) mask
3. Use paint tool (white) or selection filled with white to make parts of the image transparent.

Now look at the file size
Image

There is a difference in file sizes because each transparent pixel takes 2 more bit on hard drive than
fully opaque pixel. The difference may not be that great but this is just one layer on 800x600 px!
What if you had hundreds of layers with transparent areas?
Moreover, when GIMP developers make Layer Group masking possible,
it could save even more disk space.

Image


OK now, the Q is What can be done with alpha channel that cannot be done with masks?

Thanks


Last edited by K1TesseraEna on Wed Sep 10, 2014 9:18 pm, edited 1 time in total.

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: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 7:39 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The greatest advantage of an alpha channel over a layermask is that the pixels of a layer can be stored using pre-multiplied alpha ("Premultiplied alpha is just a different way of representing alphified pixels. If the separate alpha pixel is (r, g, b, a), then the premultiplied alpha pixel is (ar, ag, ab, a)."). This format can greatly improve the speed of, as well as simplify, many compositing operations.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 7:58 pm  (#3) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13080
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
That's an interesting question, which I've never thought about before.
Just off the top of my head, I really can't think of anything.
They seem to be interchangeable in some respects.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 8:05 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
K1TesseraEna wrote:
OK now, the Q is What can be done with alpha channel that cannot be done with masks?

Thanks[/font]

Have read at Grokking the Gimp starting at, 4.2 Layer Masks.

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


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 9:02 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
Thanks for the responses guys.

@ saulgoode. Never heard of the PMA before.
Did some search and read more. I understand the concept but regarding my question it is still chinese to me.
In practical terms, is this somehow affecting the quality if one chooses masks over alpha channels in gimp?
Or, does it produce the results that can't be achieved by using just the layer masks? Do we have a choice between
PMA and non-PMA workflow or it just pertains to the linear/non-linear color conversion of the gimp inner workings?

I saw some picture examples (fringes and fireflies of 3d renders) but can't translate it into gimp language.
Some examples would be greatly appreciated. In gimp, of course.

@Odin 4.2.1 Creating a Layer Mask
To create a layer mask, make the desired layer active in the Layers dialog and choose Add Layer Mask from the Layers menu. This creates the layer mask, but only if the active layer already has an alpha channel. If it does not have an alpha channel create one using Add Alpha Channel from the Layers menu.


This must be old (Gimp 2.4?) In my attached file Image_Mask, I added Black (full transparency) mask without adding alpha channel.
The whole point is that you don't have to do that (add alpha channel to a layer) to create transparency.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 9:53 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
Re-read this thread again and realized that maybe I wasn't explicit enough.
Edited the initial post to describe the workflows, although it could be read from the attached
gimp files.

My question in bold pertains to GIMP only.
I understand the potential of alpha channels in general.
E.g. in Photoshop you can add grayscale image to the alpha channel (e.g. depth map) to control the variable DOF. GIMP does like this idea, so you have to
use focus blur plugin to achieve the effect.
I even made the post about it here. PS or not, afaik this is not possible to do with just the layer masks.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Wed Sep 10, 2014 10:49 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
K1TesseraEna wrote:
OK now, the Q is What can be done with alpha channel that cannot be done with masks?

You can save or use a single Curves preset that modifies the color and transparency of a layer (this would require two separate Curves presets to perform with masks). Similarly for Levels presets.

Paint tools handle opacity and blending properly (with layermasks, behavior would be as though the Alpha Lock for the layer has been checked) -- especially notable with the smudge and convolve paint tools. Also, paint tool Dynamics can be configured such that alpha is affected by tilt, pressure, angle, et cetera.

Some filter operations (e.g., Value Propagate, Drop Shadow, Alpha To Logo*) can be based upon the alpha channel. Others (e.g., Gaussian blur) operate on alpha as well as RGB.

Some filters behave differently if there exists an alpha channel (e.g., "Filter->Render->Flames"). Map Object also treats a fully transparent alpha specially.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 1:29 am  (#8) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
K1TesseraEna wrote:
Thanks for the responses guys.
@Odin 4.2.1 Creating a Layer Mask
To create a layer mask, make the desired layer active in the Layers dialog and choose Add Layer Mask from the Layers menu. This creates the layer mask, but only if the active layer already has an alpha channel. If it does not have an alpha channel create one using Add Alpha Channel from the Layers menu.


This must be old (Gimp 2.4?) In my attached file Image_Mask, I added Black (full transparency) mask without adding alpha channel.
The whole point is that you don't have to do that (add alpha channel to a layer) to create transparency.
Yup, Grokking the Gimp is related to older versions of Gimp but much of the technical information is valid useful.

I can see what you mean about using a layer mask only as a different way to work with transparency. The disadvantage of not using an Alpha channel is some filters might not work. I suppose an advantage would be you can lock an Alpha channel.

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


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 3:56 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
saulgoode wrote:
The greatest advantage of an alpha channel over a layermask is that the pixels of a layer can be stored using pre-multiplied alpha ("Premultiplied alpha is just a different way of representing alphified pixels. If the separate alpha pixel is (r, g, b, a), then the premultiplied alpha pixel is (ar, ag, ab, a)."). This format can greatly improve the speed of, as well as simplify, many compositing operations.

sorry for my ignorance, Saulgoode, but:
- how can I create a "multiplied alpha"? (which command)
thanks

_________________
"Where am I ?"


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 4:49 am  (#10) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
K1TesseraEna wrote:
@ saulgoode. Never heard of the PMA before.
Did some search and read more. I understand the concept but regarding my question it is still chinese to me.
In practical terms, is this somehow affecting the quality if one chooses masks over alpha channels in gimp?
Or, does it produce the results that can't be achieved by using just the layer masks? Do we have a choice between
PMA and non-PMA workflow or it just pertains to the linear/non-linear color conversion of the gimp inner workings?


dinasset wrote:
sorry for my ignorance, Saulgoode, but:
- how can I create a "multiplied alpha"? (which command)
thanks

This was my mistake. Pre-multiplied alpha is handled internally by GIMP and users aren't really exposed to it. In this sense I'd misinterpreted K1TesseraEna's question/post. Sorry.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 6:26 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
@Saulgoode
that's a pity, it looked as a promising way of handling channels (not only internally, but also user driven)

edit: by googling I found an article about http://kevin.c.krinke.ca/2012/04/24/creating-images-with-pre-multiplied-alpha-using-gimp/
did you try it?

_________________
"Where am I ?"


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 1:34 pm  (#12) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
It is getting interesting.
Plugins! Yes, I forgot about them. But still not convinced.
That's right, many plugins will add alpha channel to your image but not because they have to.
It's the shortcut and easier way of doing things because gimp has an alpha channel in PDB for the script to use it.
Doesn't necessarily mean they can't get the job done using layer masks.

I looked up the plugin browser. All the plugins that require RGBA are the third party plugins.
Image

Indeed, drop shadow, outer/inner glow, Alpha to Logo add alpha channel. First thing they do.
But it's not a must.
Here's a drop shadow I made just with just the layer mask. As the bold font of the layer names suggests - there is no alpha channel added.

Image

I also managed to make a gaussian blur (doesn't require RGBA, btw) by making a selection with feathered edges where radius
corresponds to gaussian blur x,y values.
The only (technical) problem is that feather edge higher value is limited to 100 px compared to practically infinite value in G.blur ,
and you can't do it separately by x,y coordinates but I'm pretty sure it's doable with some code intervention.
I found a workaround for Paint tool (brush) opacity as well. Haven't tries the Smudge tool and brush dynamics yet but I will.
Blending modes reliance on alpha channel vs layer masks is more difficult to grasp. But his is a math. Layer masks are the grayscale images.
How difficult it is to interpolate rgb(a) values to grayscale gamut? There are some limitations, of course, but i think with 16-bit grayscale mode
these limitations will be close to zero.

@dinasset After adding pre-multiplied alpha to the image following the described technique, I added the original image as a top layer
set to Difference mode. This way you can detect the faintest changes done to the image.
The resulting image is 100% black (r=0, g=0, b=0, A=255) with flat histogram on Alpha channel.
I might be wrong but that means only one thing - there was no change to the image at all.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 1:54 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
I found this post https://mail.gnome.org/archives/gimp-user-list/2012-September/msg00332.html
So, maybe it doesn't swing the pendulum either way. Both have their pros and cons. ;)


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 3:42 pm  (#14) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
K1TesseraEna wrote:
I found this post https://mail.gnome.org/archives/gimp-user-list/2012-September/msg00332.html
So, maybe it doesn't swing the pendulum either way. Both have their pros and cons. ;)
That's an interesting post at [Gimp-user] list. Did you notice the author who started the [Gimp-user] alpha channels vs masks topic was the one you commented about in this thread, Subject: Targeting matching Color Profile? Color Management?
Anyway, it looks like your having fun with this one K1TesseraEna. :smiley2

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


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Thu Sep 11, 2014 4:17 pm  (#15) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
K1TesseraEna wrote:
The resulting image is 100% black (r=0, g=0, b=0, A=255) with flat histogram on Alpha channel.
I might be wrong but that means only one thing - there was no change to the image at all.

When the value of a color component is zero, it doesn't matter what the value of the alpha is; (pre-)multiplying anything by zero results in zero. For black, the value of each of the color channels is zero, so pre-multiplied alpha for black is identical to separate alpha black.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Fri Sep 12, 2014 10:05 am  (#16) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
@Odin I've been wondering if someone's questioned indispensability of these two major features before.
I guess I was looking in the wrong place. Well, my topic may sound the same but has a completely different angle.
After reading the answers I found that they've made 2 wrong assumptions.

@saulgoode The alpha value is from the resulting (merged) image. Just wanted to emphasize that the image indeed had an alpha channel.
What's your opinion on the technique. Can we really create pixels with PMA this way?
I expressed my doubts but need someone with more knowledge to confirm or prove me wrong.
And how would you compare the same image before and after adding PMA?
Is Difference blending mode right in such cases?


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Fri Sep 12, 2014 11:13 am  (#17) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
K1TesseraEna wrote:
@saulgoode The alpha value is from the resulting (merged) image. Just wanted to emphasize that the image indeed had an alpha channel.

A PMA pixel has the same alpha channel value as a separate alpha pixel -- "If the separate alpha pixel is (r, g, b, a), then the premultiplied alpha pixel is (ar, ag, ab, a)."

K1TesseraEna wrote:
What's your opinion on the technique. Can we really create pixels with PMA this way?
I expressed my doubts but need someone with more knowledge to confirm or prove me wrong.

The technique presented in the tutorial produces the correct result (though it could be done slightly more efficiently).
K1TesseraEna wrote:
And how would you compare the same image before and after adding PMA?

If you had a layer presenting a PMA pixmap, then to view it in its original, "normal" representation, you would:
  • Add a layermask initialized using "Transfer layer's alpha channel".
  • Copy the layermask to the clipboard.
  • Paste the clipboard to a new layer (above the original).
  • Set the layer blend mode of the new layer to Divide.
Owing to GIMP's 8-bit color limitation, there will be roundoff error, but the result would be mathematically correct (and the error would be miniscule when using 32-bit floating point color).

Bear in mind that the PMA image you see in GIMP will never appear the same as a separate alpha image. The tutorial to which you linked was designed to create an image that could be exported to a different program -- GIMP always assumes that a separate alpha color representation is being used (though internally it may use PMA for compositing previews).

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Masks vs alpha channels
PostPosted: Fri Sep 12, 2014 11:18 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
OK, got it. Thanks Saul!


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Toolbox and Dialog Box for Layers/Paths/Channels, etc.

26

No new posts Help with masks and layers please!

3

No new posts Attachment(s) ofn-luminosity-masks

8

No new posts Attachment(s) New Luminosity Masks Scripts

6

No new posts Attachment(s) Playing with masks and other small effects

11



* Login  



Powered by phpBB3 © phpBB Group