O'Reilly logo

Python Multimedia Beginner's Guide by Ninad Sathaye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - adjusting brightness and contrast

Let's learn how to modify the image brightness and contrast. First, we will write code to adjust brightness. The ImageEnhance module makes our job easier by providing Brightness class.

  1. Download image 0165_3_12_Before_BRIGHTENING.png and rename it to Before_BRIGHTENING.png.
  2. Use the following code:
    1 import Image
    2 import ImageEnhance
    3
    4 brightness = 3.0
    5 peak = Image.open( "C:\\images\\Before_BRIGHTENING.png ")
    6 enhancer = ImageEnhance.Brightness(peak)
    7 bright = enhancer.enhance(brightness)
    8 bright.save( "C:\\images\\BRIGHTENED.png ")
    9 bright.show()
    
  3. On line 6 in the code snippet, we created an instance of the class Brightness. It takes Image instance as an argument.
  4. Line 7 creates a new image ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required