-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlayoutOpen.py
More file actions
162 lines (128 loc) · 4.73 KB
/
layoutOpen.py
File metadata and controls
162 lines (128 loc) · 4.73 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
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
import time
from PyQt4 import QtCore
import sys
from PyQt4 import QtGui
import os
import Kmean
import thread
from PIL import Image
from skimage import io
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
img=""
class Ui_Form(QtGui.QWidget):
def __init__(self):
super(Ui_Form, self).__init__()
self.setupUi()
def setupUi(self):
hbox = QtGui.QHBoxLayout(self)
self.topleft = QtGui.QFrame()
self.topleft.setFrameShape(QtGui.QFrame.StyledPanel)
self.topright = QtGui.QFrame()
self.topright.setFrameShape(QtGui.QFrame.StyledPanel)
self.top = QtGui.QFrame()
self.top.setFrameShape(QtGui.QFrame.StyledPanel)
self.splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.splitter1.addWidget(self.topleft)
self.splitter1.addWidget(self.topright)
self.splitter1.setSizes([20,80])
self.splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
self.splitter2.addWidget(self.top)
self.splitter2.addWidget(self.splitter1)
self.splitter2.setSizes([30,80])
self.progressBar = QtGui.QProgressBar(self.topright)
self.progressBar.setGeometry(QtCore.QRect(100, 13, 508, 23))
self.progressBar.setProperty("value", 10)
self.progressBar.setTextVisible(False)
self.progressBar.setObjectName(_fromUtf8("progressBar"))
self.pic = QtGui.QLabel(self.topright)
self.pic.setGeometry(10, 20, 350, 400)
self.pic2 = QtGui.QLabel(self.topright)
self.pic2.setGeometry(380, 20, 350, 400)
self.runButton = QtGui.QPushButton("run",self.topright)
self.runButton.setGeometry(QtCore.QRect(20, 10, 70, 30))
self.runButton.setObjectName(_fromUtf8("runButton"))
self.runButton.clicked.connect(self.onStart)
open_btn = QtGui.QPushButton('Open', self.top)
open_btn.resize(170,40)
open_btn.move(25, 10)
open_btn.clicked.connect(self.showDialog)
self.fileText = QtGui.QLabel(self.top)
self.fileText.setGeometry(205,10,500,40)
self.inputfile = QtGui.QLabel(self.topright)
self.inputfile.setGeometry(20,425,200,40)
self.runingAlgo = QtGui.QLabel(self.topright)
self.runingAlgo.setGeometry(620,7,200,40)
self.runingAlgo.setText("Choose file")
self.inputfile.setText("INPUT IMAGE ")
self.outputfile = QtGui.QLabel(self.topright)
self.outputfile.setGeometry(390,425,200,40)
self.outputfile.setText("OUTPUT IMAGE")
openFile = QtGui.QAction(QtGui.QIcon('open.png'), 'Open', self.top)
openFile.setShortcut('Ctrl+O')
openFile.setStatusTip('Open new File')
openFile.triggered.connect(self.showDialog)
"""menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openFile)"""
self.myLongTask = TaskThread()
self.myLongTask.taskFinished.connect(self.onFinished)
hbox.addWidget(self.splitter2)
self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.setGeometry(100, 100, 1000, 800)
self.setWindowTitle('Image Segmentation tool kit')
self.show()
def onStart(self):
global img
if img!="" :
self.progressBar.setRange(0,0)
self.runingAlgo.setText(" Running....")
self.myLongTask.start()
else:
self.runingAlgo.setText("No file choosen...")
def onFinished(self):
# Stop the pulsation
self.runingAlgo.setText(" Done !")
self.progressBar.setRange(0,1)
pixmap = QtGui.QPixmap(os.getcwd()+"/test.jpg")
pixmap3 = pixmap.scaled(300,300, QtCore.Qt.KeepAspectRatio)
self.pic2.setPixmap(pixmap3)
def showDialog(self):
self.fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file', os.getcwd())
global img
img=self.fname
self.fileText.setText(str(img))
pixmap = QtGui.QPixmap(self.fname)
pixmap3 = pixmap.scaled(300,300, QtCore.Qt.KeepAspectRatio)
self.pic.setPixmap(pixmap3)
def test(self):
for i in xrange(500000):
print i
class TaskThread(QtCore.QThread):
taskFinished = QtCore.pyqtSignal()
def run(self):
global img
li=img.split('/')
file1=li[len(li)-1]
data=io.imread(str(img))
data=Kmean.kmean(data,10,5)
im = Image.fromarray(data)
im.save(os.getcwd()+"/test.jpg")
self.taskFinished.emit()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
ui = Ui_Form()
ui.show()
sys.exit(app.exec_())