-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_editing_cmd_line.py
165 lines (153 loc) · 4.81 KB
/
image_editing_cmd_line.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from utils.basic import load, save, saveNT, saveN, showImage, bgr
from manipulations.hue import (
greyscale,
invert,
solarize,
contrast,
brightness,
gamma,
cPop,
cIPop,
)
from manipulations.blur import meanBlur, gaussBlur
def resize(im, x, y):
return im.resize((x, y))
def currUpdate(ch):
global curr, curr_max
if ch == "+":
curr += 1
if curr > curr_max:
curr_max = curr
if ch == "-":
curr -= 1
def firstLoad():
global im, curr
cmd = input(">>> load ")
cmd = cmd.split(" ")
im.append(load(cmd[0]))
curr += 1
def getIn():
global im, curr, undone, curr_max
cmd = input(">>> ")
cmd = cmd.split(" ")
match cmd[0]:
case "help":
print(
"""Note:\t* [] means optional
\t* all values are taken as float unless mentioned otherwise
General Commands:
* load <filename>.<extension>
* save [<filename>] [<extension>]
* exit [save]
* show [<filename>.<extension>]
* undo
* redo
Image Manipulation Commands:
* greyscale
* invert
* solarize <"<" or ">"> <threshold value from 0 to 255>
* contrast <value from -100 to 100>
* resize <new number (integer) of rows> <new number (integer) of columns>
* brightness <value from -100 to 100>
* gamma correction <gamma value>
* color pop <color name in English> [invert]
* mean blur <kernel size (integer)>
* gaussian blur <kernel size (integer)> [<sigma value, default sigma = 1>]
* bgr <color name in English>"""
)
case "exit":
if len(cmd) >= 2:
if cmd[1] == "save":
save(im[curr])
exit()
else:
exit()
else:
exit()
case "load":
im.append(load(cmd[1]))
currUpdate("+")
case "save":
if len(cmd) == 3:
saveNT(im[curr], cmd[1], cmd[2])
elif len(cmd) == 2:
saveN(im[curr], cmd[1])
else:
save(im[curr])
case "show":
if len(cmd) == 1:
showImage(im[curr])
elif len(cmd) == 2:
im1 = load(cmd[1])
showImage(im1)
case "greyscale":
im.append(greyscale(im[curr]))
currUpdate("+")
case "invert":
im.append(invert(im[curr]))
currUpdate("+")
case "solarize":
if len(cmd) >= 3:
im.append(solarize(im[curr], cmd[1], float(cmd[2])))
currUpdate("+")
case "contrast":
if len(cmd) >= 2:
im.append(contrast(im[curr], float(cmd[1])))
currUpdate("+")
case "resize":
if len(cmd) >= 3:
im.append(resize(im[curr], int(cmd[1]), int(cmd[2])))
currUpdate("+")
case "brightness":
if len(cmd) >= 2:
im.append(brightness(im[curr], float(cmd[1])))
currUpdate("+")
case "gamma":
if len(cmd) >= 3:
if cmd[1] == "correction":
im.append(gamma(im[curr], float(cmd[2])))
currUpdate("+")
case "color":
if len(cmd) == 3:
if cmd[1] == "pop":
im.append(cPop(im[curr], cmd[2]))
currUpdate("+")
if len(cmd) == 4:
if cmd[1] == "pop" and cmd[3] == "invert":
im.append(cIPop(im[curr], cmd[2]))
currUpdate("+")
case "mean":
if len(cmd) >= 3:
if cmd[1] == "blur":
im.append(meanBlur(im[curr], int(cmd[2])))
currUpdate("+")
case "gaussian":
if len(cmd) == 3:
if cmd[1] == "blur":
im.append(gaussBlur(im[curr], int(cmd[2]), 1))
currUpdate("+")
elif len(cmd) >= 4:
if cmd[1] == "blur":
im.append(gaussBlur(im[curr], int(cmd[2]), float(cmd[3])))
currUpdate("+")
case "bgr":
if len(cmd) >= 2:
print(bgr(cmd[1]))
case "undo":
if curr != 0:
undone.append(im.pop())
currUpdate("-")
case "redo":
if len(undone) > 0:
im.append(undone.pop())
curr += 1
case _:
pass
im = []
curr = -1
curr_max = -1
undone = []
print("Python Image Editing Command-line: UE20MA251 Project\nSemester 4: APR 2022\nSYNTAX:\tload <image name>.<extension>\nEnter 'help' for more information.")
firstLoad()
while True:
getIn()