From 7d49c8f38cc5325bd87701b54086a3f9c499b7ac Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 2 Jul 2020 19:14:24 +1000 Subject: [PATCH 1/2] Updated documentation --- src/PIL/ImageOps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 008ec0238..157da0b52 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -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. """ @@ -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]: From 4b5eab4c1762910c3d80b10ec8b7dc1eb6a7939f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 2 Jul 2020 19:01:56 +1000 Subject: [PATCH 2/2] Simplified code --- Tests/test_imageops.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index 9938aff28..864df447e 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -305,11 +305,9 @@ def test_exif_transpose(): 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))