-
Notifications
You must be signed in to change notification settings - Fork 1
/
project1Widget.py
executable file
·98 lines (87 loc) · 3.65 KB
/
project1Widget.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QWidget, QLabel, QLineEdit, QPushButton, \
QHBoxLayout, QVBoxLayout, QSizePolicy, \
QFileDialog
from PyQt5.QtCore import Qt, pyqtSlot, QPoint
from imageViewerWidget import imageViewerWidget
from histWidget import histWidget
class project1Widget(QWidget):
def __init__(self, processor, parent=None):
super(project1Widget, self).__init__(parent=parent)
# variables
self.processor = processor
# layout
self.histViewer = histWidget()
self.labelThreshold = QLabel('Threshold')
self.editThreshold = QLineEdit()
self.btnThreshold = QPushButton('Accept')
self.btnOtsu = QPushButton('OTSU')
self.btnEntropy = QPushButton('Entropy Method')
self.btnOpen = QPushButton('Open Image')
hbox = QHBoxLayout()
hbox.addWidget(self.btnOtsu)
hbox.addWidget(self.btnEntropy)
hbox.addWidget(self.labelThreshold)
hbox.addWidget(self.editThreshold)
hbox.addWidget(self.btnThreshold)
hbox.addWidget(self.btnOpen)
vbox = QVBoxLayout()
vbox.addWidget(self.histViewer)
vbox.addLayout(hbox)
self.setLayout(vbox)
# connect inner signals
#self.btnOtsu.clicked.connect(lambda \
# p=self.processor, e=self.editThreshold: \
# e.setText('{:}'.format(processor.getOtsuThreshold())))
#self.btnEntropy.clicked.connect(lambda \
# p=self.processor, e=self.editThreshold: \
# e.setText('{:}'.format(processor.getEntropyThreshold())))
self.btnOtsu.clicked.connect(lambda \
p=self.processor, h=self.histViewer: \
h.setValue(processor.getOtsuThreshold()))
self.btnEntropy.clicked.connect(lambda \
p=self.processor, h=self.histViewer: \
h.setValue(processor.getEntropyThreshold()))
#self.histViewer.valueChanged.connect(lambda value, \
# p=self.processor: \
# p.setThreshold(value))
self.histViewer.valueChanged.connect(lambda value, \
e=self.editThreshold: \
e.setText('{:}'.format(value)))
# connect outer signals
self.btnThreshold.clicked.connect(lambda \
p=self.processor, e=self.editThreshold: \
processor.setThreshold(float(e.text())))
self.processor.thresholdChanged.connect(lambda value, \
e=self.editThreshold:
e.setText('{:}'.format(value)))
self.processor.thresholdChanged.connect(lambda value, \
h=self.histViewer:
h.setValue(value))
self.processor.imageChanged.connect(lambda \
p=self.processor, h=self.histViewer:
h.setImage(p.getImage()))
self.btnOpen.clicked.connect(self.actLoadImage)
def actLoadImage(self):
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.ExistingFile)
dialog.setViewMode(QFileDialog.Detail)
#dialog.setOption(QFileDialog.ShowDirsOnly, True)
if dialog.exec_():
imgPath = str(dialog.selectedFiles()[0])
self.processor.loadImage(imgPath)
if __name__ == '__main__':
import sys, os
from PyQt5.QtWidgets import QApplication
from imageProcessor import binaryImage
imgPath = 'pics/Lenna.png'
if len(sys.argv) > 1:
imgPath = sys.argv[1]
processor = binaryImage()
app = QApplication(sys.argv)
ex = project1Widget(processor)
ex.setGeometry(300, 300, 600, 600)
ex.show()
processor.loadImage(imgPath)
sys.exit(app.exec_())