How to Brighten an Image in Python

The Python programming language can manipulate a variety of data types, including text and images. The Python Image Library, or PIL, contains a number of methods for opening and performing operations on image files. By using the PIL and its supported methods, particularly the "point" method, you can brighten or darken images and thus lighten or fade colors in any picture.

Things You'll Need

  • Python interpreter
Show More

Instructions

    • 1

      Download and install the latest version of the Python Image Library (PIL) from the Pythonware.com website.

    • 2

      Open an image file and save it into an image object using code such as the following:

      >>>from PIL import Image
      >>> im = Image.open('/home/pic.jpg')

      Replace "/home/pic.jpg" with the path and file name of the image you want to brighten.

    • 3

      Brighten the image by calling the "point" method, which will perform an operation on all the pixels in the image. The point method takes a function as an argument, so in this example, you’ll use a lambda function which multiplies each pixel value by 1.9. Multiply the pixel by a number greater than 1 to brighten or less than 1 to darken it:

      >>>changed = im.point(lambda x: x * 1.9) // ‘changed’ will contain the lightened image

Related Searches:

References

Comments

Related Ads

Featured