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.
Download image
0165_3_12_Before_BRIGHTENING.png
and rename it toBefore_BRIGHTENING.png
.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()
On line 6 in the code snippet, we created an instance of the class
Brightness
. It takesImage
instance as an argument.Line 7 creates a new image
bright
by using the specifiedbrightness
value. A value between0.0
and less than1.0
gives a darker image, whereas a value greater than1.0
makes it brighter. A value of1.0
keeps the brightness of the image unchanged.The original and resultant image...