4. ImageEnhance Contrast


4.1. Contrast

Use the ImageEnhance.Contrast(image).enhance(factor) method to return an image with adjusted contrast.
ImageEnhance.Contrast(image).enhance(factor)
factor is a floating point value controlling the enhancement. There are no restrictions on this value.
Factor 1.0 always returns a copy of the original image.
lower factors mean less contrast, and higher values more.
from PIL import Image, ImageEnhance


with Image.open("test_images/alph_blocks.png") as im:
    new_im = ImageEnhance.Contrast(im).enhance(0.5)
    new_im.save("enhanced/contrast0_5.png")
    new_im = ImageEnhance.Contrast(im).enhance(0.8)
    new_im.save("enhanced/contrast0_8.png")
    new_im = ImageEnhance.Contrast(im).enhance(1)
    new_im.save("enhanced/contrast1.png")
    new_im = ImageEnhance.Contrast(im).enhance(1.3)
    new_im.save("enhanced/contrast1_3.png")
    new_im = ImageEnhance.Contrast(im).enhance(2)
    new_im.save("enhanced/contrast2.png")
../_images/enhanced_contrast.png

../_images/contrast.gif