[visit-developers] PIL tool to extract alpha channel

Sean Ahern ahern at ornl.gov
Wed Oct 1 15:30:32 EDT 2008


There are many times where I want to get an alpha channel from an image 
I'm generating in VisIt.  This really isn't possible in many cases, 
since we don't keep alpha around in the frame buffer.  It's especially 
difficult for really transparent volume renderings.

However, it's possible to calculate an alpha channel by rendering an 
image twice, once with a white background and again with a black 
background.  You can then do some math to calculate alpha and what the 
original R,G,B values are.

I've created a python script using PIL that does this work.  I've 
attached it here.  USAGE: alpha.py whiteImage blackImage outputImage

As an example, I've also attached some PNGs and an output PNG that 
demonstrate the script.  I ran it as "alpha white.png black.png 
output.png".  (Yes, I know I also changed the foreground color.  Doesn't 
really hurt.)

Enjoy!

-Sean

__
Sean Ahern
Oak Ridge National Laboratory
AIM: ornlsean
865-241-3748
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: alpha.py
URL: <https://email.ornl.gov/pipermail/visit-developers/attachments/20081001/c5cf7928/alpha-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: white.png
Type: image/png
Size: 104723 bytes
Desc: not available
URL: <https://email.ornl.gov/pipermail/visit-developers/attachments/20081001/c5cf7928/white-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: black.png
Type: image/png
Size: 80302 bytes
Desc: not available
URL: <https://email.ornl.gov/pipermail/visit-developers/attachments/20081001/c5cf7928/black-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output.png
Type: image/png
Size: 143688 bytes
Desc: not available
URL: <https://email.ornl.gov/pipermail/visit-developers/attachments/20081001/c5cf7928/output-0001.png>


More information about the visit-developers mailing list