Ned Batchelder wrote:
If your image is single-channel (mode "L"), then you can use the eval
function:
img = Image.open("onechannel.png")
# at each pixel, if it isn't zero, make it 255..
better = Image.eval(img, lambda p: 255 * (int(p != 0)))
better.save("bilevel.png")
if you want to avoid the clever lambda, you can use "point" instead,
with a precalculated lookup table:
# build lookup table (you can do this once, at the module level)
lut = [255] * 256 # make everything white
lut[0] = 0 # except things that are already pure black
...
better = img.point(lut) # for each image
</F>
_______________________________________________
Image-SIG maillist - Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig