python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.29k stars 2.23k forks source link

Is the Docs information about Image.convert(method='1') incorrect? #4430

Closed damondpham closed 4 years ago

damondpham commented 4 years ago

The Docs state binary conversion makes all non-zero values white, and all zero values black: https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#PIL.Image.Image.convert

But, if I read in an image, it looks like it uses a halfway point instead:

Image.open('my_image.jpg').convert(mode='1', dither=False)

Here is the image file I tried: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fchildrensdentistryofcharlottesville.com%2Fwp-content%2Fuploads%2F2017%2F01%2Fblack-white-spectrum.jpg&f=1&nofb=1

It also says "If dither is NONE, all non-zero values are set to 255 (white)." This should be "If dither is False, ...", right?

hugovk commented 4 years ago

You've linked to the v3.1 docs from 2016. This:

If dither is NONE, all non-zero values are set to 255 (white).

has since been changed (in https://github.com/python-pillow/Pillow/pull/3397) to:

If dither is NONE, all values larger than 128 are set to 255 (white), all other values to 0 (black).

https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.convert

hugovk commented 4 years ago

It also says "If dither is NONE, all non-zero values are set to 255 (white)." This should be "If dither is False, ...", right?

Checking the source, if dither is None (not NONE which equals NEAREST and 0), dither is set to FLOYDSTEINBERG.

And NONE and FLOYDSTEINBERG give different results:

The default method of converting a greyscale (“L”) or “RGB” image into a bilevel (mode “1”) image uses Floyd-Steinberg dither to approximate the original image luminosity levels. If dither is NONE, all values larger than 128 are set to 255 (white), all other values to 0 (black).

damondpham commented 4 years ago

ah, perfect. thanks so much for your help!

hugovk commented 4 years ago

You're welcome!