[BangPypers] Convert to Black and White to an image

Roshan Mathews rmathews at gmail.com
Fri Jan 7 18:30:50 CET 2011


On Fri, Jan 7, 2011 at 22:04, Narendra Sisodiya
<narendra at narendrasisodiya.com> wrote:
> Can somebody give an easy way to convert a image into black and white using
> a given threshold..
>
> Currently I am doing like this
>
>    image=ImageOps.grayscale(image)
>    for i in range(0,width):
>        for j in range(0,height):
>            if image.getpixel((i,j)) <= 200:
>                image.putpixel((i,j),0)
>
What's the problem with your code?  What you're doing is called image
binarization, afaik.  Thresholding is the basic way to do it, are you
unhappy with the results, or the speed of execution?  If it is speed,
the docs at http://www.pythonware.com/library/pil/handbook/image.htm
say you should consider using `getdata' ...

> What is the general mailing list to ask question on python ?
>
This is one.
There is also: http://mail.python.org/mailman/listinfo/baypiggies
And http://mail.python.org/mailman/listinfo/python-list


-- 
http://about.me/rosh


More information about the BangPypers mailing list