Python Pillow – Adjust Image Brightness

Python – Adjust Image Brightness using Pillow Library

You can adjust the brightness of an image using Python Pillow library. Adjusting the brightness mean, either increasing the pixel value evenly across all channels for the entire image to increase the brightness, or decreasing the pixel value evenly across all channels for the entire image to decrease the brightness.

Increasing the brightness makes image whiter. And decreasing brightness darkens the image.

Steps to Adjust Image Brightness using PIL

To adjust image brightness using Python Pillow,

  1. Read the image using Image.open().
  2. Create ImageEnhance.Brightness() enhancer for the image.
  3. Enhance the image brightness using enhance() method, by the required factor.

By adjusting the factor you can brighten or dull the image.

While a factor of 1 gives original image. Making the factor towards 0 makes the image black, while factor>1 brightens the image.

Examples

1. Increate given image brightness

In the following example, we will brighten the image by a factor of 1.5, which gives a brightened image.

Python Program

from PIL import Image, ImageEnhance

# Read the image
im = Image.open("sample-image.png")

# Image brightness enhancer
enhancer = ImageEnhance.Brightness(im)

factor = 1 #gives original image
im_output = enhancer.enhance(factor)
im_output.save('original-image.png')

factor = 1.5 #brightens the image
im_output = enhancer.enhance(factor)
im_output.save('brightened-image.png')
Copy

Original Image

Python Pillow - Adjust Image Brightness - Brighten the image

Brightened Image – With increased brightness

Python Pillow - Adjust Image Brightness - Brighten the image

2. Decrease the brightness of given image

In the following example, we will decrease the brighten the image by a factor of 0.5, which gives a darkened image.

Python Program

from PIL import Image, ImageEnhance

# Read the image
im = Image.open("sample-image.png")

# Image brightness enhancer
enhancer = ImageEnhance.Brightness(im)

factor = 1 #gives original image
im_output = enhancer.enhance(factor)
im_output.save('original-image.png')

factor = 0.5 #darkens the image
im_output = enhancer.enhance(factor)
im_output.save('darkened-image.png')
Copy

Original Image

Python Pillow - Adjust Image Brightness - Brighten the image

Darkened Image – With decreased brightness

Python Pillow - Adjust Image Brightness - Brighten the image

Summary

In this tutorial of Python Examples, we learned how to brighten an image, with the help of well detailed Python programs.

Related Tutorials

Code copied to clipboard successfully 👍