-
Notifications
You must be signed in to change notification settings - Fork 1
/
T15_interactive_ui.py
115 lines (93 loc) · 3.9 KB
/
T15_interactive_ui.py
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
104
105
106
107
108
109
110
111
112
113
114
115
# ECOR1051 Milestone 3 P8: Interactive User Interface
# Lab Session: L-1A
# Team 15: The Brogrammers
# Date of Submission: April 2, 2020
# Team Members:
# Dorothy Tran
# Kian Zalzalah
# Joahkim Vaudrin-Moisan
from Cimpl import *
from T15_image_filters import *
def user_interface()->str:
"""Author: Dorothy Tran
.......
L)oad imagee S)ave as
2)-tone 3)-tone X)treme contrast T)int sepia P)osterize
E)dge detect I)mproved edge detect V)ertical flip H)orizontal flip
Q)uit
:
"""
print ('L)oad imagee 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')
print()
input_filter=input(': ',).upper()
return input_filter
commands = ['L','S','2','3','X','T','P','E','I','V','H','Q']
def apply_filter(selected_filter:int)->Image:
"""Author: Dorothy Tran
.......
>>>input_filter=user_interface()
>>>apply_filter(input_filter)
"""
image_loaded = False
if selected_filter == commands[11]:
image = None
print('No Image Loaded')
selected_filter = user_interface()
while selected_filter != commands[11]:
if selected_filter in commands:
if selected_filter == commands[0]:
image_loaded = True
image = load_image(choose_file())
show(image)
elif selected_filter == commands[1]:
new_image = copy(image)
save_as(new_image,'filtered_image.jpg')
elif selected_filter == commands[2]:
new_image = copy(image)
two_toned = two_tone(new_image,'yellow','cyan')
show(two_toned)
elif selected_filter == commands[3]:
new_image = copy(image)
three_toned = three_tone(new_image,'yellow','cyan','magenta')
show(three_toned)
elif selected_filter == commands[4]:
new_image = copy(image)
contrast_image = extreme_contrast(new_image)
show(contrast_image)
elif selected_filter == commands[5]:
new_image = copy(image)
sepia_tone = sepia(new_image)
show(sepia_tone)
elif selected_filter == commands[6]:
new_image = copy(image)
posterized_image = posterize(new_image)
show(posterized_image)
elif selected_filter == commands[7]:
new_image = copy(image)
threshold=input('Enter a Threshold Value: ')
edge_detection = detect_edges(new_image,int(threshold))
show(edge_detection)
elif selected_filter == commands[8]:
new_image = copy(image)
threshold=input('Enter a Threshold Value: ')
improved_edge_detection = detect_edges_better(new_image,int(threshold))
show(improved_edge_detection)
elif selected_filter == commands[9]:
new_image = copy(image)
vertical_flip_image = flip_vertical(new_image)
show(vertical_flip_image)
elif selected_filter == commands[10]:
new_image = copy(image)
horizontal_flip_image = flip_horizontal(new_image)
show(horizontal_flip_image)
elif image_loaded != True:
print ('No Image Loaded')
selected_filter = user_interface()
else:
print('No Such Command')
selected_filter = user_interface()
input_filter=user_interface()
apply_filter(input_filter)