-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
241 lines (209 loc) · 9.76 KB
/
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
import sys
from scan import Scan
from raw_data import RawData
import matplotlib.pyplot as plt
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout, QHBoxLayout, QTabWidget, QWidget, \
QFileDialog, QStatusBar, QLabel, QPlainTextEdit, QLayout, QFrame
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
class Window(QDialog):
"https://stackoverflow.com/questions/12459811/how-to-embed-matplotib-in-pyqt-for-dummies"
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.raw_data = None
self.scan = None
# First figure
self.figure1 = plt.figure()
self.canvas1 = FigureCanvas(self.figure1)
self.toolbar1 = NavigationToolbar(self.canvas1, self)
self.figure_element1 = QVBoxLayout()
self.figure_element1.addWidget(self.canvas1)
self.figure_element1.addWidget(self.toolbar1)
# Second figure
self.figure2 = plt.figure()
self.canvas2 = FigureCanvas(self.figure2)
self.toolbar2 = NavigationToolbar(self.canvas2, self)
self.figure_element2 = QVBoxLayout()
self.figure_element2.addWidget(self.canvas2)
self.figure_element2.addWidget(self.toolbar2)
# Third figure
self.figure3 = plt.figure()
self.canvas3 = FigureCanvas(self.figure3)
self.toolbar3 = NavigationToolbar(self.canvas3, self)
self.figure_element3 = QVBoxLayout()
self.figure_element3.addWidget(self.canvas3)
self.figure_element3.addWidget(self.toolbar3)
# Fourth figure
self.figure4 = plt.figure()
self.canvas4 = FigureCanvas(self.figure4)
self.toolbar4 = NavigationToolbar(self.canvas4, self)
self.figure_element4 = QVBoxLayout()
self.figure_element4.addWidget(self.canvas4)
self.figure_element4.addWidget(self.toolbar4)
# Fifth figure
self.figure5 = plt.figure()
self.canvas5 = FigureCanvas(self.figure5)
self.toolbar5 = NavigationToolbar(self.canvas5, self)
self.figure_element5 = QVBoxLayout()
self.figure_element5.addWidget(self.canvas5)
self.figure_element5.addWidget(self.toolbar5)
# Sixth figure
self.figure6 = plt.figure()
self.canvas6 = FigureCanvas(self.figure6)
self.toolbar6 = NavigationToolbar(self.canvas6, self)
self.figure_element6 = QVBoxLayout()
self.figure_element6.addWidget(self.canvas6)
self.figure_element6.addWidget(self.toolbar6)
# Buttons
self.button_load_raw = QPushButton("Load raw data")
self.button_load_raw.clicked.connect(self.load_raw)
self.button_process_raw = QPushButton("Process raw data")
self.button_process_raw.clicked.connect(self.process_raw)
self.button_load_ascans = QPushButton("Load ascans")
self.button_load_ascans.clicked.connect(self.load_ascans)
self.button_process_ascans = QPushButton("Process ascans")
self.button_process_ascans.clicked.connect(self.process_ascans)
# Text Edit's
self.diameter_min = QLabel("Diameter (min): ")
self.diameter_max = QLabel("Diameter (max): ")
self.diameter_average = QLabel("Diameter (average): ")
self.diameter_min_text = QPlainTextEdit("...")
self.diameter_min_text.setMaximumHeight(30)
self.diameter_max_text = QPlainTextEdit("...")
self.diameter_max_text.setMaximumHeight(30)
self.diameter_average_text = QPlainTextEdit("...")
self.diameter_average_text.setMaximumHeight(30)
self.layout_diameter = QHBoxLayout()
self.layout_diameter.addWidget(self.diameter_min)
self.layout_diameter.addWidget(self.diameter_min_text)
self.layout_diameter.addWidget(self.diameter_max)
self.layout_diameter.addWidget(self.diameter_max_text)
self.layout_diameter.addWidget(self.diameter_average)
self.layout_diameter.addWidget(self.diameter_average_text)
# Layouts
self.layout_buttons1 = QHBoxLayout()
self.layout_buttons1.addWidget(self.button_load_raw)
self.layout_buttons1.addWidget(self.button_process_raw)
self.layout_buttons2 = QHBoxLayout()
self.layout_buttons2.addWidget(self.button_load_ascans)
self.layout_buttons2.addWidget(self.button_process_ascans)
self.layout_tab_raw = QVBoxLayout()
self.layout_tab_ascan = QVBoxLayout()
self.layout_raw_first_row = QHBoxLayout()
self.layout_raw_first_row.addLayout(self.figure_element1)
self.layout_raw_first_row.addWidget(self.VLine())
self.layout_raw_first_row.addLayout(self.figure_element2)
self.layout_raw_second_row = QHBoxLayout()
self.layout_raw_second_row.addLayout(self.figure_element3)
self.layout_raw_second_row.addWidget(self.VLine())
self.layout_raw_second_row.addLayout(self.figure_element4)
self.layout_ascan_first_row = QHBoxLayout()
self.layout_ascan_first_row.addLayout(self.figure_element5)
self.layout_ascan_first_row.addWidget(self.VLine())
self.layout_ascan_first_row.addLayout(self.figure_element6)
self.layout_tab_raw.addLayout(self.layout_buttons1)
self.layout_tab_raw.addWidget(self.HLine())
self.layout_tab_raw.addLayout(self.layout_raw_first_row)
self.layout_tab_raw.addWidget(self.HLine())
self.layout_tab_raw.addLayout(self.layout_raw_second_row)
self.layout_tab_ascan.addLayout(self.layout_buttons2)
self.layout_tab_ascan.addWidget(self.HLine())
self.layout_tab_ascan.addLayout(self.layout_ascan_first_row)
self.layout_tab_ascan.addWidget(self.HLine())
self.layout_tab_ascan.addLayout(self.layout_diameter)
# Tab Widget
self.tab_widget = QTabWidget()
self.tab_raw_data = QWidget()
self.tab_ascans = QWidget()
self.tab_raw_data.setLayout(self.layout_tab_raw)
self.tab_ascans.setLayout(self.layout_tab_ascan)
self.tab_widget.addTab(self.tab_raw_data, "Raw data from OCT system")
self.tab_widget.addTab(self.tab_ascans, "Preprocessed image from IVOCT")
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.tab_widget)
self.status_bar = QStatusBar()
self.status_bar_text = QLabel("Starting succesfully finished")
self.status_bar.addWidget(self.status_bar_text)
layout.addWidget(self.status_bar)
self.setLayout(layout)
def HLine(self):
toto = QFrame()
toto.setFrameShape(QFrame.HLine)
toto.setFrameShadow(QFrame.Sunken)
return toto
def VLine(self):
toto = QFrame()
toto.setFrameShape(QFrame.VLine)
toto.setFrameShadow(QFrame.Sunken)
return toto
def load_raw(self):
path, _ = QFileDialog.getOpenFileName(self, 'Open binary file', '', "Binary (*.bin)")
if path != "":
self.status_bar_text.setText("Loading raw data")
# Loading raw data
self.raw_data = RawData(20000)
self.raw_data.load_raw_data(path)
# 5 raw ascans
self.figure1.clear()
ax = self.figure1.add_subplot(111)
ax.plot(self.raw_data.cut_spectra[:, 120:125])
self.canvas1.draw()
# 5000 raw ascans
self.figure3.clear()
ax = self.figure3.add_subplot(111)
ax.imshow(self.raw_data.cut_spectra)
self.canvas3.draw()
self.status_bar_text.setText("Finished loading raw data")
else:
self.status_bar_text.setText("Path was empty!")
def process_raw(self):
if self.raw_data is not None:
self.status_bar_text.setText("Processing raw data")
self.raw_data.process_raw_data()
# 5 processed ascans
self.figure2.clear()
ax = self.figure2.add_subplot(111)
ax.plot(self.raw_data.cut_spectra[:, 120:125])
self.canvas2.draw()
# processed image
self.figure4.clear()
ax = self.figure4.add_subplot(111)
ax.imshow(self.raw_data.cut_spectra)
self.canvas4.draw()
self.status_bar_text.setText("Finished processing raw data")
def load_ascans(self):
path, _ = QFileDialog.getOpenFileName(self, 'Open b-scan file', '', "B Scans (*.bin)")
if path != "":
self.status_bar_text.setText("Loading processed data")
# Loading Scan
self.scan = Scan(20000)
self.scan.load_data(path)
# 5000 processed ascans
self.figure5.clear()
ax = self.figure5.add_subplot(111)
ax.imshow(self.scan.cut_matrix)
self.canvas5.draw()
self.status_bar_text.setText("Finished loading processed data")
else:
self.status_bar_text.setText("Path was empty!")
def process_ascans(self):
if self.scan is not None:
self.status_bar_text.setText("Processing polar view")
self.scan.find_peaks()
self.scan.plot_cut_matrix()
self.scan.create_polar_views()
# polar_view = self.scan.interpolation_polar_view(self.scan.polar_views[2], 3)
# Show polar view
self.figure6.clear()
ax = self.figure6.add_subplot(111)
for i in range(0, len(self.scan.polar_views)):
ax(i).imshow(self.scan.polar_views[i])
self.canvas6.draw()
self.status_bar_text.setText("Finished processing polar view")
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Window()
main.setWindowTitle("Intravascular Optical Coherence Tomograph - Viewer")
main.show()
sys.exit(app.exec_())