9951 explained code solutions for 126 technologies

python-pillowHow to auto contrast an image

from PIL import Image, ImageOps

im = Image.open('/var/www/examples/heroine.png')

im = ImageOps.autocontrast(im, cutoff = 5)
im.show()ctrl + c

import Pillow package modules


open given image with Pillow


path to sample image to open


set contrast automatically based on given cutoff

cutoff = 5

defines part of histogram (in percents) that should be removed


displays resulting image