Saturday, December 28, 2024
Google search engine
HomeLanguagesPython | ImageOps.autocontrast()method

Python | ImageOps.autocontrast()method

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:




# Importing Image and ImageOps module from PIL package  
from PIL import Image, ImageOps 
    
# creating a image1 object 
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPg")
     
# applying autocontrast method 
im2 = ImageOps.autocontrast(im1, cutoff = 2, ignore = 2)
  
im2.show() 


Output:




# Importing Image and ImageOps module from PIL package  
from PIL import Image, ImageOps 
    
# creating a image1 object 
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPg")
     
# applying autocontrast method 
im2 = ImageOps.autocontrast(im1, cutoff = 5, ignore = 5)
  
im2.show() 


Output:

RELATED ARTICLES

Most Popular

Recent Comments