-
Notifications
You must be signed in to change notification settings - Fork 8
/
Editing_GUI.py
executable file
·292 lines (180 loc) · 9.37 KB
/
Editing_GUI.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env python
import Tkinter as tk
from Tkinter import *
from tkFileDialog import askopenfilename, askdirectory
from PIL import Image, ImageTk
import sys,os
import numpy as np
from Grabcut_app_tkinter import *
from Copy_Paste_Insert_Delete_app_tkinter import *
from Recoloring_app_tkinter import *
from Local_Alpha_Matting_app_tkinter import *
from Thickness_Scattering_Weights_modification_app_tkinter import *
class Main_app:
def __init__(self, master):
self.master=master
self.master.title('Inital Window')
Welcome = """\nWelcome to PigMania!\n\nPlease click "File" Menu to start.\n"""
self.msg = Message(self.master, text = Welcome, width=600)
self.msg.config(bg='lightgreen', font=('times', 24, 'italic'))
self.msg.pack()
#### menu for different task
menu = tk.Menu(master)
self.master.config(menu=menu)
filemenu = tk.Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Open processed example image", command=self.OpenFile)
filemenu.add_separator()
filemenu.add_command(label="Grabcut", command=self.Grabcut)
filemenu.add_separator()
filemenu.add_command(label="Copy_Paste_Insert_Delete", command=self.Copy_Paste_Insert_Delete)
filemenu.add_separator()
filemenu.add_command(label="Recoloring", command=self.Recoloring)
# filemenu.add_separator()
# filemenu.add_command(label="Thickness, Scattering and Weights modification", command=self.Thickness_Scattering_Weights_modification)
filemenu.add_separator()
filemenu.add_command(label="Local_Alpha_Matting", command=self.Local_Alpha_Matting)
# filemenu.add_separator()
# filemenu.add_command(label="Open unprocessed example image and Extract pigments", command=self.OpenFile_version2)
filemenu.add_separator()
filemenu.add_command(label="Reset", command=self.Reset)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=master.quit)
helpmenu = tk.Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About", command=self.About)
self.mask=None
self.control=0
def Show_image(self, img, option=0):
self.master.title('Main window')
width,height=img.size
# print width, height
if option==0:
self.canvas = tk.Canvas(self.master, width=width, height=height, highlightthickness=0, borderwidth=0, cursor="cross")
self.canvas.pack(side="top", fill="both", expand=True)
else:
self.canvas.config(width=width, height=height)
self.canvas.pack(side="top", fill="both", expand=True)
self.tk_im = ImageTk.PhotoImage(img)
self.canvas.create_image(0,0,anchor="nw",image=self.tk_im)
def Reset(self):
self.Show_image(self.im, option=1)
def About(self):
print "####"
class AllData(): ### to collect all datas.
def __init__(self):
self.KM_pigments=None
self.KM_weights=None
self.KM_thickness=None
self.PD_vertices=None
self.PD_weights=None
self.PD_opacities=None
self.Pig_order=None
self.Existing_KS=None
def OpenFile(self): #### open a processed image and all other files together.
self.name = askopenfilename()
self.directory=os.path.split(self.name)[0]
print self.name
print self.directory
self.im=Image.open(self.name).convert('RGB')
self.img2=np.asarray(self.im)
self.msg.pack_forget() ###remove message box and show image.
self.Show_image(self.im, option=self.control)
self.control=1
self.path_prefix=os.path.splitext(self.name)[0]
self.OpenFile0()
self.OpenFile1()
self.OpenFile2()
self.OpenFile3()
self.OpenFile4()
self.OpenFile5()
self.OpenFile6()
self.OpenFile7()
print "Finish loading all data!"
def OpenFile0(self):
name=self.directory+"/order1.txt"
self.AllData.Pig_order=np.loadtxt(name).astype(np.uint8)
self.PigNum=len(self.AllData.Pig_order)
print self.PigNum
print self.AllData.Pig_order
def OpenFile1(self):
name=self.path_prefix+"-"+str(self.PigNum)+"-primary_pigments_KS.txt"
self.AllData.KM_pigments=np.loadtxt(name)
print self.AllData.KM_pigments.shape
self.AllData.KM_pigments=self.AllData.KM_pigments[self.AllData.Pig_order, :] ### reorder
def OpenFile2(self):
# ### read txt is slow
# name=self.path_prefix+"-"+str(self.PigNum)+"-KM_mixing-weights.txt"
# self.AllData.KM_weights=np.loadtxt(name)
# self.AllData.KM_weights=self.AllData.KM_weights.reshape((self.img2.shape[0],self.img2.shape[1],self.AllData.KM_weights.shape[-1]))
self.AllData.KM_weights=np.zeros((self.img2.shape[0],self.img2.shape[1],self.PigNum))
for i in range(self.PigNum):
name=self.path_prefix+"-"+str(self.PigNum)+"-KM_mixing-weights_map-%02d.png"%i
self.AllData.KM_weights[:,:,i]=np.asarray(Image.open(name).convert('L'))/255.0
print self.AllData.KM_weights.shape
self.AllData.KM_weights=self.AllData.KM_weights[:,:,self.AllData.Pig_order] ### reorder
def OpenFile3(self):
# ###read txt file is slow
# name=self.path_prefix+"-"+str(self.PigNum)+"-KM_layers-order1-thickness.txt"
# self.AllData.KM_thickness=np.loadtxt(name)
# self.AllData.KM_thickness=self.AllData.KM_thickness.reshape((self.img2.shape[0],self.img2.shape[1],self.AllData.KM_thickness.shape[-1]))
self.AllData.KM_thickness=np.zeros((self.img2.shape[0],self.img2.shape[1],self.PigNum))
for i in range(self.PigNum):
name=self.path_prefix+"-"+str(self.PigNum)+"-KM_layers-order1-thickness_map-%02d.png"%i
self.AllData.KM_thickness[:,:,i]=np.asarray(Image.open(name).convert('L'))/255.0
self.AllData.KM_thickness+=1e-11
print self.AllData.KM_thickness.shape
def OpenFile4(self):
name=self.path_prefix+"-"+str(self.PigNum)+"-primary_pigments_RGB_color.js"
with open(name) as myfile:
self.AllData.PD_vertices=np.asarray(json.load(myfile)['vs'])
print self.AllData.PD_vertices.shape
self.AllData.PD_vertices=self.AllData.PD_vertices[self.AllData.Pig_order, :] ### reorder
def OpenFile5(self):
# #### reading js file is slow
# name=self.path_prefix+"-"+str(self.PigNum)+"-PD_mixing-weights.js"
# with open(name) as myfile:
# self.AllData.PD_weights=np.asarray(json.load(myfile)['weights'])
# self.AllData.PD_weights=self.AllData.PD_weights.reshape((self.img2.shape[0],self.img2.shape[1],self.AllData.PD_weights.shape[-1]))
self.AllData.PD_weights=np.zeros((self.img2.shape[0],self.img2.shape[1],self.PigNum))
for i in range(self.PigNum):
name=self.path_prefix+"-"+str(self.PigNum)+"-PD_mixing-weights_map-%02d.png"%i
self.AllData.PD_weights[:,:,i]=np.asarray(Image.open(name).convert('L'))/255.0
print self.AllData.PD_weights.shape
self.AllData.PD_weights=self.AllData.PD_weights[:,:,self.AllData.Pig_order] ### reorder
def OpenFile6(self):
# ### reading txt file is slow
# name=self.path_prefix+"-"+str(self.PigNum)+"-PD_layers-order1-opacities.txt"
# self.AllData.PD_opacities=np.loadtxt(name)
# self.AllData.PD_opacities=self.AllData.PD_opacities.reshape((self.img2.shape[0],self.img2.shape[1],self.AllData.PD_opacities.shape[-1]))
self.AllData.PD_opacities=np.zeros((self.img2.shape[0],self.img2.shape[1],self.PigNum))
for i in range(self.PigNum):
name=self.path_prefix+"-"+str(self.PigNum)+"-PD_layers-order1-opacities_map-%02d.png"%i
self.AllData.PD_opacities[:,:,i]=np.asarray(Image.open(name).convert('L'))/255.0
print self.AllData.PD_opacities.shape
def OpenFile7(self):
name=self.directory+"/Existing_KS_parameter_KS.txt"
self.AllData.Existing_KS=np.loadtxt(name)
print self.AllData.Existing_KS.shape
def Grabcut(self):
global grabcut_app
grabcut_app=Grabcut_app(self)
def Copy_Paste_Insert_Delete(self):
global copy_paste_insert_delete_app
copy_paste_insert_delete_app=Copy_Paste_Insert_Delete_app(self)
def Recoloring(self): ### can local or global
global recoloring_app
recoloring_app=Recoloring_app(self)
# def Thickness_Scattering_Weights_modification(self):
# thickness_scattering_weights_modification_app=Thickness_Scattering_Weights_modification_app(self)
def Local_Alpha_Matting(self):
local_alpha_matte_app=Local_Alpha_Matting_app(self)
def OpenFile_version2(self): ### open a unprocessed image only, for extracting palette from given image
# import step1_ANLS_with_autograd
### only parameter is pignum (4-7) and other parameters are fixed for GUI.
pass
if __name__ == "__main__":
# base_dir = os.path.split( os.path.realpath(__file__) )[0]
root=tk.Tk()
app = Main_app(root)
root.mainloop()