[Image-SIG] Filtering out all but black pixels for OCR
karsten.hiddemann at mathematik.uni-dortmund.de
Wed Jul 2 13:47:45 CEST 2008
Ned Batchelder schrieb:
> If your image is single-channel (mode "L"), then you can use the eval
> 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)))
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
More information about the Image-SIG