[Image-SIG] Image.convert() doesn't dither?

Fredrik Lundh fredrik at pythonware.com
Tue Oct 25 11:04:32 CEST 2005

Bill Janssen wrote:

> The PIL manual says that calling image.convert('1') on a greyscale
> image will threshold the image (fairly starkly: "all non-zero values
> are set to 255 (white).")  However, when I try this on a test page of
> color blocks, I seem to get Floyd-Steinberg dithering instead.

> Is the documentation out of date?

most likely.

the draft version at http://effbot.org/imagingbook/image.htm says

    When converting to a bilevel image (mode "1"), the source image
    is first converted to black and white. Resulting values larger than
    127 are then set to white, and the image is dithered. To use other
    thresholds, use the point method.

(but it doesn't mention the dither option, so it needs to be fixed too)

> If I want thresholding, is there a now a way to do it without using
> "point"?  Using quantize(), perhaps?

    im = im.convert("1", dither=Image.NONE)

should work.

> Is there a difference between Image.convert('L') and
> ImageOps.grayscale()?


    def grayscale(image):
        "Convert to grayscale"
        return image.convert("L")

(all ImageOps operations can be rewritten in terms of core operations;
that module's only purpose is to provide a higher-level interface for some
commonly used operations.  not all operations are quite as trivial as the
one above, though...)


More information about the Image-SIG mailing list