File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ from PIL import Image
2
+
3
+
4
+ def change_brightness (img : Image , level : float ) -> Image :
5
+ """
6
+ Change the brightness of a PIL Image to a given level.
7
+ """
8
+
9
+ def brightness (c : int ) -> float :
10
+ """
11
+ Fundamental Transformation/Operation that'll be performed on
12
+ every bit.
13
+ """
14
+ return 128 + level + (c - 128 )
15
+
16
+ if not - 255.0 <= level <= 255.0 :
17
+ raise ValueError ("level must be between -255.0 (black) and 255.0 (white)" )
18
+ return img .point (brightness )
19
+
20
+
21
+ if __name__ == "__main__" :
22
+ # Load image
23
+ with Image .open ("image_data/lena.jpg" ) as img :
24
+ # Change brightness to 100
25
+ brigt_img = change_brightness (img , 100 )
26
+ brigt_img .save ("image_data/lena_brightness.png" , format = "png" )
You can’t perform that action at this time.
0 commit comments