mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-05 00:13:42 +03:00
ImageOps autocontrast cutoff updated
This commit is contained in:
parent
cc83723d6b
commit
fb2a184eed
|
@ -88,12 +88,18 @@ def autocontrast(image, cutoff=0, ignore=None):
|
||||||
h[ix] = 0
|
h[ix] = 0
|
||||||
if cutoff:
|
if cutoff:
|
||||||
# cut off pixels from both ends of the histogram
|
# cut off pixels from both ends of the histogram
|
||||||
|
if isinstance(cutoff, int):
|
||||||
|
cutoff = (cutoff, cutoff)
|
||||||
|
elif isinstance(cutoff, tuple):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ValueError("the cutoff can only be a integer or tuple")
|
||||||
# get number of pixels
|
# get number of pixels
|
||||||
n = 0
|
n = 0
|
||||||
for ix in range(256):
|
for ix in range(256):
|
||||||
n = n + h[ix]
|
n = n + h[ix]
|
||||||
# remove cutoff% pixels from the low end
|
# remove cutoff% pixels from the low end
|
||||||
cut = n * cutoff // 100
|
cut = n * cutoff[0] // 100
|
||||||
for lo in range(256):
|
for lo in range(256):
|
||||||
if cut > h[lo]:
|
if cut > h[lo]:
|
||||||
cut = cut - h[lo]
|
cut = cut - h[lo]
|
||||||
|
@ -104,7 +110,7 @@ def autocontrast(image, cutoff=0, ignore=None):
|
||||||
if cut <= 0:
|
if cut <= 0:
|
||||||
break
|
break
|
||||||
# remove cutoff% samples from the hi end
|
# remove cutoff% samples from the hi end
|
||||||
cut = n * cutoff // 100
|
cut = n * cutoff[1] // 100
|
||||||
for hi in range(255, -1, -1):
|
for hi in range(255, -1, -1):
|
||||||
if cut > h[hi]:
|
if cut > h[hi]:
|
||||||
cut = cut - h[hi]
|
cut = cut - h[hi]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user