Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocontrast cutoff behaves unexpectedly #3331

Closed
jnweiger opened this issue Sep 4, 2018 · 1 comment
Closed

Autocontrast cutoff behaves unexpectedly #3331

jnweiger opened this issue Sep 4, 2018 · 1 comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects

Comments

@jnweiger
Copy link

jnweiger commented Sep 4, 2018

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

@radarhere radarhere changed the title autocontrast cutoff behaves unexpectedly Autocontrast cutoff behaves unexpectedly Sep 5, 2018
@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label May 11, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to Icebox in Pillow May 11, 2019
@radarhere
Copy link
Member

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.

If you don't specify cutoff=2, then the result matches this part of the expectation.

https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.autocontrast

This function calculates a histogram of the input image (or mask region), removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255).

I think your expectation is that the cutoff would apply after scaling, whereas Pillow is applying it before scaling. This behaviour is what is described in the documentation, so I don't think there's anything to do here.

Pillow automation moved this from Icebox to Closed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
Pillow
  
Closed
Development

No branches or pull requests

3 participants