Image Brightness Enhancement Function

  • Share this:

Code introduction


This function is used to enhance the brightness of an image. It reads an image from a specified path, uses the Brightness enhancer from the ImageEnhance module, enhances the image brightness by a given factor, and saves the enhanced image to a specified path.


Technology Stack : Pillow

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
from PIL import Image, ImageEnhance, ImageFilter

def enhance_image_brightness(image_path, output_path, factor=2):
    # Load the image
    image = Image.open(image_path)
    
    # Enhance brightness
    enhancer = ImageEnhance.Brightness(image)
    enhanced_image = enhancer.enhance(factor)
    
    # Save the enhanced image
    enhanced_image.save(output_path)                
              
Tags: