-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu_unsuper.py
270 lines (208 loc) · 5.7 KB
/
menu_unsuper.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
from Tkinter import *
import tkMessageBox
import tkFileDialog
import math
import numpy
import tkColorChooser
import sys
sys.path.append('./K-means')
import kmeanswork as km
import numpy as np
sys.path.append('./ISODATA')
import isodata as iso
sys.path.append('./fuzzy')
import fuzzy as fz
filename=''
iteration=0
def unsuper(no):
global filename
global iteration
global box1
global root
root=Tk()
root.geometry('350x350')
root.title('Unsupervised Classification')
count=0
global i
i=0
global text
text=0
global clustervalue,add2
clustervalue=numpy.array([])
global l1,l2,l3,hexc,rgb
global clusterarray
clusterarray=[]
global colorArr
colorArr = []
global className
className = []
def end():
global root
root.destroy()
def showfilename(filen):
tkMessageBox.showinfo('File Chosen',filen)
def help_tab():
tkMessageBox.showinfo("Help","You are too dumb")
def browse():
global filename
filename=tkFileDialog.askopenfilename(filetypes=[("TIF File","*.tif")])
showfilename(filename)
print filename
def changecolor():
global hexcsp
global i
global rgb
hexc='hexc'+str(i+1)
(rgb,hexc)=tkColorChooser.askcolor()
#print hexc
#print rgb
l3.configure(bg=hexc)
def endfield():
global add
add.destroy()
stopaddition.destroy()
global add2
add2=Button(framebutton,text='Add More',command=addfield )
add2.pack()
def createfield(name,framename):
name=Entry(framename,width=5)
name.pack()
def addfield():
global i
global clustervalue
global l2
global clusterarray
global box1
global rgb
global colorArr
global className
global iteration
cname=l2.get()
#print cname
className.append(cname)
clustervalue=[i,cname,rgb]
colorArr.append(rgb)
#print clustervalue
#print colorArr
clusterarray.append(clustervalue)
i=i+1
iterationnum=box1.get()
clusternum=i
#print "No. of Iterations: ",iterationnum
#print "No. of Clusters: ",clusternum
#print clusterarray
def changecolor2():
global rgb
global hexc
global i
rgb='rgb'+str(i+1)
hexc='hexc'+str(i+1)
(rgb,hexc)=tkColorChooser.askcolor()
#print rgb
l3.configure(bg=hexc)
outerframe='outerframe'+str(i+1)
#print outerframe
l1='l1'+str(i+1)
l2='box'+str(i+1)
l3='colorchooser'+str(i+1)
outerframe=Frame(frame2)
l1=Label(outerframe,text=str(i+1),width=10)
l1.pack(side=LEFT)
l2=Entry(outerframe,width=5)
l2.pack(side=LEFT)
l3=Button(outerframe,text='Color',command=changecolor2,width=10)
l3.pack(side=LEFT)
outerframe.pack(side=TOP)
#print i
def setiter():
global iteration
text=box1.get()
a=len(text)
if a == 0 :
tkMessageBox.showerror('Error','Enter value !')
pass
else:
print text
iteration=int(text)
outerframe=numpy.array([])
innerframe1=numpy.array([])
colorbox=numpy.array([])
def unsupervised():
global filename
global iteration
print colorArr
print className
print filename
if (filename == ''):
browse()
if (no == 1):
km.kmea(colorArr,iteration,filename)
if (no == 2):
x = {'K':len(colorArr) , 'I':iteration}
iso.isoclass(filename, colorArr,x)
if (no == 3):
fz.fuzz(colorArr,filename)
# create a toplevel menu
menubar = Menu(root)
filemenu2=Menu(menubar,tearoff='0')
filemenu3=Menu(menubar,tearoff='0')
filemenu3.add_command(label='Open',command=browse)
filemenu3.add_command(label='Close',command=end)
menubar.add_cascade(label='Import File',menu=filemenu3)
# create a pulldown menu, and add it to the menu bar
menubar.add_cascade(label="Help", menu=filemenu2)
filemenu2.add_command(label="About Software", command=help_tab)
root.config(menu=menubar)
#display buttons
showimg=Button(root,text='Display Image',command= unsupervised)
showimg.pack()
#number of iterations
framec=Frame(root)
lnumiter=Label(framec,text='Enter Number of Iterations :',padx=10,pady=10)
lnumiter.pack(side=LEFT)
box1=Entry(framec,width=5)
box1.pack(side=LEFT)
submitnum=Button(framec,text='Go',command=setiter)
submitnum.pack(side=LEFT)
framec.pack(side=TOP)
#creating labels
frame1=Frame(root)
lu=Label(frame1,text='Cluster No.',width=10)
lu.pack(side=LEFT)
lu1=Label(frame1,text='Name',width=10)
lu1.pack(side=LEFT)
lu2=Label(frame1,text='Color Code',width=10)
lu2.pack(side=LEFT)
frame1.pack(side=TOP)
global frame2
frame2=Frame(root)
#print text
global arrayvalue
arrayvalue=numpy.array([])
outerframe='outerframe'+str(i+1)
#print outerframe
l1='l1'+str(i+1)
l2='box'+str(i+1)
l3='colorchooser'+str(i+1)
outerframe=Frame(frame2)
l1=Label(outerframe,text=str(i+1),width=10)
l1.pack(side=LEFT)
l2=Entry(outerframe,width=5)
l2.pack(side=LEFT)
l3=Button(outerframe,text='Color',command=changecolor,width=10)
l3.pack(side=LEFT)
outerframe.pack(side=TOP)
frame2.pack(side=TOP)
#submit value
framebutton=Frame(root,pady=30)
global add
add=Button(framebutton,text='Add',command=addfield)
add.pack(side=LEFT)
#stopaddition=Button(framebutton,text='End Addition',command=endfield)
#stopaddition.pack(side=LEFT)
framebutton.pack(side=TOP)
iterationnum=l2.get()
clusternum=i
#print "No. of Iterations: ",iterationnum
#print "No. of Iterations: ",clusternum
root.mainloop()