mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Add preserve_tone option to autocontrast
This commit is contained in:
parent
ddcc936643
commit
c585e6ab6b
|
@ -29,6 +29,7 @@ def test_sanity():
|
|||
ImageOps.autocontrast(hopper("L"), cutoff=(2, 10))
|
||||
ImageOps.autocontrast(hopper("L"), ignore=[0, 255])
|
||||
ImageOps.autocontrast(hopper("L"), mask=hopper("L"))
|
||||
ImageOps.autocontrast(hopper("L"), preserve_tone=True)
|
||||
|
||||
ImageOps.colorize(hopper("L"), (0, 0, 0), (255, 255, 255))
|
||||
ImageOps.colorize(hopper("L"), "black", "white")
|
||||
|
|
|
@ -61,7 +61,7 @@ def _lut(image, lut):
|
|||
# actions
|
||||
|
||||
|
||||
def autocontrast(image, cutoff=0, ignore=None, mask=None):
|
||||
def autocontrast(image, cutoff=0, ignore=None, mask=None, preserve_tone=False):
|
||||
"""
|
||||
Maximize (normalize) image contrast. This function calculates a
|
||||
histogram of the input image (or mask region), removes ``cutoff`` percent of the
|
||||
|
@ -77,9 +77,14 @@ def autocontrast(image, cutoff=0, ignore=None, mask=None):
|
|||
:param mask: Histogram used in contrast operation is computed using pixels
|
||||
within the mask. If no mask is given the entire image is used
|
||||
for histogram computation.
|
||||
:param preserve_tone: Preserve image tone in Photoshop-like style autocontrast.
|
||||
:return: An image.
|
||||
"""
|
||||
histogram = image.histogram(mask)
|
||||
if preserve_tone:
|
||||
histogram = image.convert("L").histogram(mask)
|
||||
else:
|
||||
histogram = image.histogram(mask)
|
||||
|
||||
lut = []
|
||||
for layer in range(0, len(histogram), 256):
|
||||
h = histogram[layer : layer + 256]
|
||||
|
|
Loading…
Reference in New Issue
Block a user