-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path107_interactive_ui.py
More file actions
103 lines (76 loc) · 2.43 KB
/
107_interactive_ui.py
File metadata and controls
103 lines (76 loc) · 2.43 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Author: Ramadan Mohamed, Aditya Wiwekananda, David Lefebvre, Talal Jaber
from T107_image_filters import *
def showMenu() -> None:
"""Displays the menu of
commands
>>> showMenu()
"""
print("L)oad image S)ave-as")
print("2)-tone 3)-tone X)treme contrast T)int sepia P)osterize")
print("E)dge detect I)mproved edge detect V)ertical flip H)orizontal flip")
print("Q)uit\n")
def enterCommand() -> str:
"""Displays the menu of
commands and prompts the
user to enter an input.
Returns the string input
>>> enterCommand()
"""
showMenu()
return input(": ").upper()
def checkValid(command: str) -> None:
"""Takes a command and displays
whether they have inputed an
invalid command or if they
did not load an image
>>> checkValid('xyz')
"""
if command in ['S', '2', '3', 'X', 'T', 'P', 'E', 'I', 'V', 'H']:
print("No image loaded\n")
else:
print("No such command\n")
def applyFilter(command: str, image: Image) -> Image:
"""Takes a command and an image
and applys the corresponding
filter to the image"""
if command == '2':
image = two_tone(image, 'yellow', 'cyan')
elif command == '3':
image = three_tone(image, 'yellow', 'magenta', 'cyan')
elif command == 'X':
image = extreme_contrast(image)
elif command == 'T':
image = sepia(image)
elif command == 'P':
image = posterize(image)
elif command == 'E':
image = detect_edges(image, float(input("Threshold?: ")))
elif command == 'I':
image = detect_edges_better(image, float(input("Threshold?: ")))
elif command == 'V':
image = flip_vertical(image)
elif command == 'H':
image = flip_horizontal(image)
return image
command = True
loaded = False
validCommands = ['L', 'Q', 'S', '2', '3', 'X', 'T', 'P', 'E', 'I', 'V', 'H']
while command != 'Q':
command = enterCommand()
if command in validCommands:
if command == 'L':
image = load_image(choose_file())
show(image)
loaded = True
elif command == 'Q':
#The while loop ends
pass
elif loaded == False:
print("No image loaded\n")
elif command == 'S':
save_as(image)
else:
image = applyFilter(command, image)
show(image)
else:
print("No such command\n")