forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_brightness.py
26 lines (20 loc) · 751 Bytes
/
change_brightness.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fromPILimportImage
defchange_brightness(img: Image, level: float) ->Image:
"""
Change the brightness of a PIL Image to a given level.
"""
defbrightness(c: int) ->float:
"""
Fundamental Transformation/Operation that'll be performed on
every bit.
"""
return128+level+ (c-128)
ifnot-255.0<=level<=255.0:
raiseValueError("level must be between -255.0 (black) and 255.0 (white)")
returnimg.point(brightness)
if__name__=="__main__":
# Load image
withImage.open("image_data/lena.jpg") asimg:
# Change brightness to 100
brigt_img=change_brightness(img, 100)
brigt_img.save("image_data/lena_brightness.png", format="png")