Python | ImageOps.autocontrast()method
Last Updated :
29 Jun, 2019
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. the
ImageOps module contains a number of ‘ready-made’ image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images.
ImageOps.autocontrast()
method maximizes (normalize) image contrast. This function calculates a histogram of the input image, removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255).
Syntax: PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None)
Parameters:
image: The image to process.
cutoff: How many percent to cut off from the histogram.
ignore: The background pixel value (use None for no background).
Returns: An image.
Image used:
from PIL import Image, ImageOps
im1 = Image. open (r "C:\Users\sadow984\Desktop\download2.JPg" )
im2 = ImageOps.autocontrast(im1, cutoff = 2 , ignore = 2 )
im2.show()
|
Output:
from PIL import Image, ImageOps
im1 = Image. open (r "C:\Users\sadow984\Desktop\download2.JPg" )
im2 = ImageOps.autocontrast(im1, cutoff = 5 , ignore = 5 )
im2.show()
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...