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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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() 

chevron_right


Output:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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() 

chevron_right


Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.