Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Autocontrast cutoff behaves unexpectedly

Open jnweiger opened this issue 7 years ago • 0 comments

What did you do?

python-3.6 with Pillow-5.2.0 leaf-gr Download this image as leaf-gr.jpg then start python and do

from PIL import Image, ImageOps
im = Image.open('leaf-gr.jpg')
ImageOps.autocontrast(im, cutoff=2).show()

grafik

What did you expect to happen?

The background is two light gray values. I expect both to become brighter. The foreground is darker gray values, I expect these to touch black.

Histogram stretching until the outermost gray values hit 0 and 255 respectively. Then some more linear stretching so that the outermost gray values would go 2 percent beyond, ca -5 and 260, then clip everything back to be within 0..255

What actually happened?

The background is half black 0x000000 and half white 0xffffff. That is unexpected. The darker gray of the background is in any case more than 2% percent brighter than the darkest point of the foreground. (Or we must be measuring very non-inear)

What versions of Pillow and Python are you using?

python-3.6 with Pillow-5.2.0

jnweiger avatar Sep 04 '18 23:09 jnweiger