File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
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 : Image , level : float ) -> Image :
15
+ """
16
+ Function to change contrast
17
+ """
18
+ factor = (259 * (level + 255 )) / (255 * (259 - level ))
19
+
20
+ def contrast (c : int ) -> float :
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
+ with Image .open ("image_data/lena.jpg" ) as img :
33
+ # Change contrast to 170
34
+ cont_img = change_contrast (img , 170 )
35
+ cont_img .save ("image_data/lena_high_contrast.png" , format = "png" )
Original file line number Diff line number Diff line change 5
5
numpy
6
6
opencv-python
7
7
pandas
8
+ pillow
8
9
pytest
9
10
sklearn
10
11
sympy
You can’t perform that action at this time.
0 commit comments