Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/autocontrast
Browse files Browse the repository at this point in the history
Updated documentation; Simplified code
  • Loading branch information
millionhz committed Jul 2, 2020
2 parents 27c4091 + 4b5eab4 commit 407d592
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 6 additions & 8 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,9 @@ def check(orientation_im):
def test_autocontrast_cutoff():
# Test the cutoff argument of autocontrast
with Image.open("Tests/images/bw_gradient.png") as img:
assert (
ImageOps.autocontrast(img, cutoff=10).histogram()
== ImageOps.autocontrast(img, cutoff=(10, 10)).histogram()
)
assert (
ImageOps.autocontrast(img, cutoff=10).histogram()
!= ImageOps.autocontrast(img, cutoff=(1, 10)).histogram()
)

def autocontrast(cutoff):
return ImageOps.autocontrast(img, cutoff).histogram()

assert autocontrast(10) == autocontrast((10, 10))
assert autocontrast(10) != autocontrast((1, 10))
6 changes: 4 additions & 2 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def autocontrast(image, cutoff=0, ignore=None):
becomes white (255).
:param image: The image to process.
:param cutoff: How many percent to cut off from the histogram.
:param cutoff: The percent to cut off from the histogram on the low and
high ends. Either a tuple of (low, high), or a single
number for both.
:param ignore: The background pixel value (use None for no background).
:return: An image.
"""
Expand Down Expand Up @@ -105,7 +107,7 @@ def autocontrast(image, cutoff=0, ignore=None):
cut = 0
if cut <= 0:
break
# remove cutoff% samples from the hi end
# remove cutoff% samples from the high end
cut = n * cutoff[1] // 100
for hi in range(255, -1, -1):
if cut > h[hi]:
Expand Down

0 comments on commit 407d592

Please sign in to comment.