[Image-SIG] ImageChops.logical_and not working?

Michael Hoffman hoffman.mm at gmail.com
Wed Sep 7 18:07:10 CEST 2005

Hello. Using PIL 1.1.5, I am trying to do logical ands on bitmap
images using ImageChops.logical_and. I seem to always get completely 
black images instead, however.

Here's a simple testcase:

import Image, ImageChops, ImageDraw

im1 = Image.new("1", (50, 50))
im2 = im1.copy()
im3 = im1.copy()

draw1 = ImageDraw.Draw(im1)
draw1.rectangle([0, 0, 40, 40], fill=255)

draw2 = ImageDraw.Draw(im2)
draw2.rectangle([10, 10, 50, 50], fill=255)


# this doesn't work:
ImageChops.logical_and(im1, im2).show()

# I expect it to work like this:
im3.putdata([x1 & x2 for x1, x2 in zip(im1.getdata(), im2.getdata())])

# this does work:
ImageChops.logical_or(im1, im2).show()

Is there another way to perform a logical and operation?

Thank you,
Michael Hoffman

More information about the Image-SIG mailing list