We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c964d74 commit 98f5c59Copy full SHA for 98f5c59
digital_image_processing/change_contrast.py
@@ -0,0 +1,35 @@
1
+"""
2
+Changing contrast with PIL
3
+
4
+This algorithm is used in
5
+https://noivce.pythonanywhere.com/ python web app.
6
7
+python/black: True
8
+flake8 : True
9
10
11
+from PIL import Image
12
13
14
+def change_contrast(img, level: int):
15
+ """
16
+ Function to change contrast
17
18
+ factor = (259 * (level + 255)) / (255 * (259 - level))
19
20
+ def contrast(c):
21
22
+ Fundamental Transformation/Operation that'll be performed on
23
+ every bit.
24
25
+ return 128 + factor * (c - 128)
26
27
+ return img.point(contrast)
28
29
30
+if __name__ == "__main__":
31
+ # Load image
32
+ img = Image.open("image_data/lena.jpg")
33
+ # Change contrast to 170
34
+ cont_img = change_contrast(img, 170.0)
35
+ cont_img.save("image_data/lena_high_contrast.png", format="png")
0 commit comments