ImageEnhance Module in Pillow

Hello Programers! In this tutorial, we are going to take a look at the ImageEnchance module in the pillow library.

This module contains a number of classes that are used for Image enhancement. This is one of the most useful modules for image manipulation. In this tutorial, we will be covering different classes in the ImageEnchance module.

Classes in the ImageEnhance module

  1. enhance():
    This method returns the enhanced image. It takes a factor parameter. It is a floating-point value. The value 1.0 returns a copy of the original image. And less the factor value lower the color(it includes brightness, sharpness, contrast, etc) and vice versa.
  2. Color():
    This class returns an enhanced image. The only thing it requires is an image. This class is used to adjust the color balance of the image. This class is mostly used to enhance the color of the image. The factor value if set to 0.0 will give a black and white image. And the factor value 1.0 will give an original image.

    from PIL import ImageEnhance, Image
    
    img = Image.open('pic1.jpg')
    
    factor = 0.0
    enhancer = ImageEnhance.Color(img)
    enhancer.enhance(factor).show()
    

    This will produce a black and white image as factor value is set to 0.0. You can change the factor value to observe different results.

  3. Brightness():
    This class is used to adjust the brightness of the image. The factor value, when set to 0.0, will give a black image and when the factor value is 1.0 it will give the original image.

    from PIL import ImageEnhance, Image
    
    img = Image.open('pic2.jpg')
    
    factor = 0.0
    enhancer = ImageEnhance.Brightness(img)
    enhancer.enhance(factor).show()
    

    The output will be a black image as the factor value is 0.0. You can change the factor value to observe different results.

  4. Contrast():
    This class is used to adjust the contrast of the image. The factor value set to 0.0 will give a solid grey image whereas the factor value set to 1.0 will give the original image.

    from PIL import ImageEnhance, Image
    
    img = Image.open('pic2.jpg')
    
    factor = 0.0
    enhancer = ImageEnhance.Contrast(img)
    enhancer.enhance(factor).show()
    

    As factor value is set to 0.0 it will produce a solid grey image. You can change the factor value to observe different results.

  5. Sharpness():
    This class is used to adjust the sharpness of the image. The factor value set to 0.0 will give a blurred image whereas when set to 1.0 will the original image. And if the factor value is set to 2.0 then it will give a sharpened blur image.

    from PIL import ImageEnhance, Image
    
    img = Image.open('pic2.jpg')
    
    factor = 0.0
    enhancer = ImageEnhance.Sharpness(img)
    enhancer.enhance(factor).show()
    

    It will produce a blurred image as the factor value is 0.0. You can change the factor value to observe different results.

Thank You guys for staying till the end. That’s it for today’s tutorial. In the next tutorial, we will be covering the ImageFile module in the pillow library.

Leave a Reply

Your email address will not be published.