[Image-SIG] Converting from 24-bit RGB to Black&White

Alexander Belchenko bialix at ukr.net
Thu Mar 2 22:34:37 CET 2006


As part of my application I wrote simple convertor of 24-bit RGB images
to greyscale and black&white (1-bit images).

PIL-Handbook.pdf (for version PIL 1.1.3) description of method
"im.convert(mode) => image" claims:

"When translating a greyscale image into a bilevel image (mode "1"), all
non-zero values are set to 255 (white). To use other thresholds, use the
point method."

I use PIL 1.1.5, OS Windows 2000. During testing my convertor I discover
following. When I have paletted image (mode is 'P') then converting to
black & white works as described in doc. If I have 'RGB' or 'L' mode
image then after conversion to black & white I have dithered(?) image.

Is this intended behaviour or this is a bug?

Here simple script that illustrate problem:

import Image

im = Image.open('star24bit.bmp')

im1 = im.convert('1')
im1.save('out1.bmp')

im2 = im.convert('L').convert('1')
im2.save('out2.bmp')

im3 = im.convert('P').convert('1')
im3.save('out3.bmp')


You can download testing source and result images at:

http://www.onembedding.com/off/pil-b&w.zip

--
Alexander



More information about the Image-SIG mailing list