Ned Batchelder schrieb:
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")
Ok, that's probably faster.
In my code, instead of doing "y in range(ydim-1, 0, -1)" you could use
"y in range(ydim)" instead, too, it was just taken from a program of
mine where I needed to invert the orientation of the image.
Fredrik has written something about the performance on pixel access with
some timings here: http://effbot.org/zone/pil-pixel-access.htm
Cheers,
Karsten
_______________________________________________
Image-SIG maillist - Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig