Pyhon and PIL

François Pinard pinard at iro.umontreal.ca
Tue Mar 5 18:01:05 EST 2002


[Olav Viken]

> I'm using Python Imaging Library (PIL) to convert a lot bmp-files from
> color to monochrome images.  This works, but all images are dithered
> (grayscale),

This is not really dithering.  Dithering is a way to trade spatial resolution
in favour of color resolution, by making many neighbouring pixels to use
different colours from a limited set, but with the average of these colours
approximately being the wanted one.

> what I want is to set "all colors (except white) to black".

> import Image
> im = Image.open("yellow.bmp")
> im = im.convert("1", dither=Image.NONE)
> im.save("yellow.bmp")

Maybe this would work?

    import Image
    Image.open('yellow.bmp').convert('L').point(255*[0] + [255]) \
        .convert('1').save('yellow.bmp')

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list