It is currently Tue Jul 23, 2024 10:33 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 7:48 am  (#1) 
Offline
GimpChat Member

Joined: Jul 19, 2014
Posts: 31
Forgive the cryptic title. I couldn't get a decent explanation into the character limit and I thought this title would get some of the right people here.

I want to understand the following workflow. This is to help me get to grips with channels, and is the first of two hard questions ;)

Say you have two photos of the same size. Import them into one document on separate layers. Make the top photo an arbitrary transparency, say 40%. You can now see a blend of the two photos. Export to .png or .bmp and discard the GIMP file. Delete one of the original photos. You now have your merged photo (in a lossless format) and only one of the originals, plus your knowledge about how the merge was made.

How can you use the remaining photo to recreate the other photo from the merged photo?


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: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 8:50 am  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Lumo wrote:
How can you use the remaining photo to recreate the other photo from the merged photo?

Can't be done. The merged photo contains only 60% of the original information about the bottom photo and if you have only the top photo available for reconstruction then the missing 40% is not recoverable. Likewise the merged photo contains only 40% of the info from the top photo and if the bottom photo is retained then there is no way to recover the missing 60%.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 8:59 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
See http://en.wikipedia.org/wiki/Alpha_compositing

The channel values of a given pixel in the final photo is:
Cf=aCo+(1-a)Cu

Cf: final result, Co: the picture over, Cu: the picture under, a: the opacity of the top picture.

So, if you want to recover Cu, knowing Cf and Co (typically, a watermarked picture and the watermark):
Cu=(Cf-aCo)/(1-a)

However,

- AFAIK Gimp isn't working in linear light but in some gamma-corrected color space so this is a bit theoretical,
- It's not that easy to implement with just layers and layers modes and avoiding round-off errors and value overflows.

... but I tried a long while ago, and it sort of works...

_________________
Image


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 9:12 am  (#4) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
I stand corrected. (As the saying goes, a sure way to get something done is to claim that it is impossible.)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 9:18 am  (#5) 
Offline
GimpChat Member

Joined: Jul 19, 2014
Posts: 31
ofnuts wrote:
The channel values of a given pixel in the final photo is:
Cf=aCo+(1-a)Cu
Cf: final result, Co: the picture over, Cu: the picture under, a: the opacity of the top picture.

Thank you, this is a great start. I'm having difficulty getting my head round what I do with the number(s) I would get though. If I get a value for Cu for the Red channel, I think value for the Green and Blue channels will be the same, since the same thing was done to all channels.

So I'd import the remaining photo over the merged photo... get my Cu number ready... but then what? We're well into Maths territory. I've tried to understand the Wikipedia article, but it seems to be written for mathematicians rather than for me ;)

I think that because we're just using 256 values per channel (8bit), the reversal procedure should be perfect, right?

Thank you again


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 10:37 am  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
Lumo wrote:
ofnuts wrote:
The channel values of a given pixel in the final photo is:
Cf=aCo+(1-a)Cu
Cf: final result, Co: the picture over, Cu: the picture under, a: the opacity of the top picture.

Thank you, this is a great start. I'm having difficulty getting my head round what I do with the number(s) I would get though. If I get a value for Cu for the Red channel, I think value for the Green and Blue channels will be the same, since the same thing was done to all channels.

So I'd import the remaining photo over the merged photo... get my Cu number ready... but then what? We're well into Maths territory. I've tried to understand the Wikipedia article, but it seems to be written for mathematicians rather than for me ;)

I think that because we're just using 256 values per channel (8bit), the reversal procedure should be perfect, right?

Thank you again


In practice the final image is the assembly of the red/green/blue image, each obtained by stacking the red/green/blue versions the background and overlay images with the same opacity(*). So you can really do all the computation channel by channel.

Having only 256 values is a major problem, because it leads very quickly to round-off errors, and if you implement this using layer stacking you can't even have intermediate values outside of the range.

(*) which is somewhat a restriction of the Gimp/Photoshop data model, since actual materials do not have the same opacity at all wavelengths.

_________________
Image


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 11:06 am  (#7) 
Offline
GimpChat Member

Joined: Jul 19, 2014
Posts: 31
ofnuts wrote:
Having only 256 values is a major problem, because it leads very quickly to round-off errors...

Would things be better working in 16bit and exporting to 8bit?


Top
 Post subject: Re: [Q] An advanced topic on colour channels and alpha transparency
PostPosted: Sat Jul 19, 2014 11:48 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
Lumo wrote:
ofnuts wrote:
Having only 256 values is a major problem, because it leads very quickly to round-off errors...

Would things be better working in 16bit and exporting to 8bit?


At least you reduce the roundoff errors.

_________________
Image


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Bleed Colour to Alpha

3

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

26



* Login  



Powered by phpBB3 © phpBB Group