-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage-filter
46 lines (36 loc) · 1.06 KB
/
image-filter
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
File: codeinplace_filter.py
----------------
This program implements a rad image filter.
"""
from simpleimage import SimpleImage
DEFAULT_FILE = 'images/quad.jpg'
def main():
# Get file and load image
get_file()
# Show the image before the transform
original_image = SimpleImage('images/quad.jpg')
original_image.show()
# Apply the filter
pink_image = code_in_place_filter('images/quad.jpg')
pink_image.show()
def code_in_place_filter(filename):
"""
Reads image from file specified by filename.
Makes image pink.
Returns the pink version of the image.
"""
image = SimpleImage(filename)
for pixel in image:
pixel.red = pixel.red * 1.5
pixel.green = pixel.green * 0.7
pixel.blue = pixel.blue * 1.5
return image
def get_file():
# Read image file path from user, or use the default file
filename = input('Enter image file (or press enter for default): ')
if filename == '':
filename = DEFAULT_FILE
return filename
if __name__ == '__main__':
main()