[Image-SIG] PIL: Unexpected results with Image.paste on RGBA images with transparency.

Lars Ruoff lars.ruoff at gmail.com
Mon Oct 29 16:05:28 CET 2012


Hi,

I'm new to this list, so excuse me if this is a known issue.
I didn't find anything on it on the net so far but didn't have time to
search much.

I have observed what i consider a flaw in the Image.paste algorithm when
used with transparent images.

transparent-columns.png is an image with 3 vertical black columns with
alpha=0.5, 0.2 and transparent respectively.
transparent-bars.png is an image with 2 horizontal black bars with
transparent and alpha=0.5 respectively.
(images attached)

When these two images are transparently pasted one over the other, using
the following code:

from PIL import Image
source = Image.open('transparent-columns.png')
result = Image.open('transparent-bars.png')
result.paste(source, (0, 0), source)
result.save('transparent-columns-on-bars-pil.png')

The result is unexpectet to say the least.
PIL seems to modify the transparency even in regions where only one of the
images has non-transparent values.
Very wrong in my opinion.

Doing the same manipulation in GIMP 2.6 gives what i consider the expected
result.
(attached for reference)

I guess the per-pixel transparency of the result should be result_alpha = 1
- (1-alpha1)*(1-alpha2),
where alpha1,alpha2 are the alpha channel values from the original images.

Regards,
Lars Ruoff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-bars.png
Type: image/png
Size: 315 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-columns.png
Type: image/png
Size: 383 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-columns-on-bars-gimp-2.6.png
Type: image/png
Size: 401 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-columns-on-bars-gimp-2.6-with-white-background.png
Type: image/png
Size: 406 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-columns-on-bars-pil.png
Type: image/png
Size: 390 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparent-columns-on-bars-pil-with-white-background.png
Type: image/png
Size: 363 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20121029/8f3faac5/attachment-0005.png>


More information about the Image-SIG mailing list