We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f97af65 commit 6f80ca8Copy full SHA for 6f80ca8
digital_image_processing/change_brightness.py
@@ -0,0 +1,26 @@
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")
0 commit comments