-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
2500 lines (2359 loc) · 130 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from re import sub
import numpy as np
try:
import os
except:
pass
#os.environ['KMP_DUPLICATE_LIB_OK']='True'
import matplotlib.pyplot as plt
from MyFunctions.DicomImage import DicomImage #Custom Class
import MyFunctions.Pickle_Functions as PF
import MyFunctions.Extract_Images_R as Extract_r
import MyFunctions.Extract_Images as Extract
from GUI_parts.GUIParam import GUIParameters
from GUI_parts.ParamWindow import ParamWindow
from GUI_parts.ExportWindow import ExportWindow
import time
import MyFunctions.Batch_Segmentations
import MyFunctions.Batch_Errors
import MyFunctions.Batch_Deform
###
import numpy as np
import time
import scipy.integrate
###
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QObject, QThread, pyqtSignal
from PyQt5 import QtGui
from functools import partial
###
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
###
import markdown
size_Image = 200
class MainWindow(QMainWindow):
"""
Main window of the GUI.
"""
def __init__(self):
"""Initializes the GUI Window"""
self.tabs = QTabWidget()
self.BUTTON_SIZE = 40
self.DISPLAY_HEIGHT = 35
self.current_line = 0
#self.displayImageLine = 0
self.first_pass = True
self.lineImage1D = -1
super().__init__(parent=None)
self.setMinimumSize(1200, 775)
self.setWindowTitle("TRU-IMP")
self.generalLayout = QGridLayout()
self.generalLayoutLog = QGridLayout()
self.generalLayoutReadMe = QGridLayout()
self.generalLayoutContributing = QGridLayout()
self.generalLayoutLicense = QGridLayout()
self.generalLayoutCodeOfConduct = QGridLayout()
centralWidget = QWidget(self)
self.centralWidget = centralWidget
centralWidgetLog = QWidget(self)
centralWidgetReadMe = QWidget(self)
centralWidgetContributing = QWidget(self)
centralWidgetLicense = QWidget(self)
centralWidgetCodeOfConduct = QWidget(self)
centralWidget.setLayout(self.generalLayout)
centralWidgetLog.setLayout(self.generalLayoutLog)
centralWidgetReadMe.setLayout(self.generalLayoutReadMe)
centralWidgetContributing.setLayout(self.generalLayoutContributing)
centralWidgetLicense.setLayout(self.generalLayoutLicense)
centralWidgetCodeOfConduct.setLayout(self.generalLayoutCodeOfConduct)
self.tabs.addTab(centralWidget,"Main")
self.tabs.addTab(centralWidgetLog,"Log")
self.tabs.addTab(centralWidgetReadMe,"Read Me")
self.tabs.addTab(centralWidgetContributing,"Contributing")
self.tabs.addTab(centralWidgetLicense,"License")
self.tabs.addTab(centralWidgetCodeOfConduct,"Code of Conduct")
self.setCentralWidget(self.tabs)
#First Line
self._createExtractDock()
self._createNoiseButtons()
#Next Line
#Second Line
self._createSavingDock()
self._createInfoParam()
self._createImageDisplayType()
#self._createImageDisplayBars()
#Line 4
self._createImageDisplay()
#Next Line
self._createTACImage()
#Next Line
self._create1DImage()
#Last Line
self._createExitButton()
##Creates the Log Tab
self._createLog()
##Creates the ReadMe Tab
self._createReadMe()
self._createContributing()
self._createLicense()
self._createCodeOfConduct()
#Status Bar
self._createStatusBar()
self._createProgressBar()
#self.setGeometry(0,0,100,100)
self.generalLayout.setColumnStretch(1,1)
self.generalLayout.setColumnStretch(2,1)
self.generalLayout.setColumnStretch(3,1)
self.generalLayout.setRowStretch(0,1)
self.generalLayout.setRowStretch(1,1)
self.generalLayout.setRowStretch(2,3)
self.generalLayout.setRowStretch(3,3)
self.showMaximized()
def _createLog(self):
"""Create a Log tab to keep track of the processes"""
self.logText = QTextEdit()
self.logText.setReadOnly(True)
try:
self.logText.setText(self.Image.progress_log)
except:
self.logText.setText("Nothing started")
self.generalLayoutLog.addWidget(self.logText)
self.exit3 = QPushButton("Exit")
self.exit3.setToolTip("Closes the GUI and its dependencies")
self.exit3.clicked.connect(self.closing_button)
self.exit3.setShortcut("Ctrl+Shift+E")
self.generalLayoutLog.addWidget(self.exit3)
def _createReadMe(self):
"""Creates a ReadMe tab with the ReadMe file infos"""
basedir = os.path.dirname(__file__)
self.ReadMeText = QTextEdit()
self.ReadMeText.setReadOnly(True)
try:
f = open(f'{basedir}/ReadMe.md', 'r')
htmlmarkdown = markdown.markdown( f.read() )
self.ReadMeText.setText(htmlmarkdown)
except: pass
self.generalLayoutReadMe.addWidget(self.ReadMeText)
self.exit2 = QPushButton("Exit")
self.exit2.setToolTip("Closes the GUI and its dependencies")
self.exit2.clicked.connect(self.closing_button)
self.exit2.setShortcut("Ctrl+Shift+E")
self.generalLayoutReadMe.addWidget(self.exit2)
def _createContributing(self):
"""Creates a Contributing tab with the Contributing file infos"""
basedir = os.path.dirname(__file__)
self.ContributingText = QTextEdit()
self.ContributingText.setReadOnly(True)
try:
f = open(f'{basedir}/Contributing.md', 'r')
htmlmarkdown = markdown.markdown( f.read() )
self.ContributingText.setText(htmlmarkdown)
except: pass
self.generalLayoutContributing.addWidget(self.ContributingText)
self.exit4 = QPushButton("Exit")
self.exit4.setToolTip("Closes the GUI and its dependencies")
self.exit4.clicked.connect(self.closing_button)
self.exit4.setShortcut("Ctrl+Shift+E")
self.generalLayoutContributing.addWidget(self.exit4)
def _createLicense(self):
"""Creates a License tab with the License file infos"""
basedir = os.path.dirname(__file__)
self.LicenseText = QTextEdit()
self.LicenseText.setReadOnly(True)
try:
f = open(f'{basedir}/License', 'r')
htmlmarkdown = markdown.markdown( f.read() )
self.LicenseText.setText(htmlmarkdown)
except: pass
self.generalLayoutLicense.addWidget(self.LicenseText)
self.exit5 = QPushButton("Exit")
self.exit5.setToolTip("Closes the GUI and its dependencies")
self.exit5.clicked.connect(self.closing_button)
self.exit5.setShortcut("Ctrl+Shift+E")
self.generalLayoutLicense.addWidget(self.exit5)
def _createCodeOfConduct(self):
"""Creates a Code of Conduct tab with the Code of Conduct file infos"""
basedir = os.path.dirname(__file__)
self.CodeOfConductText = QTextEdit()
self.CodeOfConductText.setReadOnly(True)
try:
f = open(f'{basedir}/CODE_OF_CONDUCT.md', 'r')
htmlmarkdown = markdown.markdown( f.read() )
self.CodeOfConductText.setText(htmlmarkdown)
except: pass
self.generalLayoutCodeOfConduct.addWidget(self.CodeOfConductText)
self.exit6 = QPushButton("Exit")
self.exit6.setToolTip("Closes the GUI and its dependencies")
self.exit6.clicked.connect(self.closing_button)
self.exit6.setShortcut("Ctrl+Shift+E")
self.generalLayoutCodeOfConduct.addWidget(self.exit6)
def _createStatusBar(self):
"""Create a status bar at the bottom of the GUI"""
self.statusBar = QStatusBar()
self.setStatusBar(self.statusBar)
self.statusBar.showMessage("Nothing started")
def _createProgressBar(self):
"""Creates a Progress Bar at the bottom of the GUI"""
self.progressBar = QProgressBar(self.centralWidget)
self.progressBar.setValue(0)
self.generalLayout.addWidget(self.progressBar,self.current_line-2,2)
def _createNoiseButtons(self):
"""Create the Noise button at the top of the GUI"""
subWidget = QWidget()
layout = QHBoxLayout()
subWidget.setLayout(layout)
self.btn_noise = QPushButton("Noise")
self.btn_noise.setShortcut("Ctrl+N")
self.btn_noise.setToolTip("Adds the noise to the images according to the selected parameters (Ctrl+N)")
self.btn_noise.clicked.connect(self.run_noise)
self.btn_deform = QPushButton("Deform.")
self.btn_deform.setShortcut("Ctrl+D")
self.btn_deform.setToolTip("Makes a deformation on a segmentation according to the selected parameters (Ctrl+D)")
self.btn_deform.clicked.connect(self.run_deform)
self.btn_erase = QPushButton("Erase")
self.btn_erase.setToolTip("Danger! Will erase a calculated aspect as specified")
self.btn_erase.clicked.connect(self.run_erase)
layout.addWidget(self.btn_noise)
layout.addWidget(self.btn_deform)
layout.addWidget(self.btn_erase)
self.generalLayout.addWidget(subWidget,self.current_line,3,1,1)
self.current_line += 1
def _createInfoParam(self):
"""Create the dock at the top from where the parameters, the infos and the lauch buttons are"""
subWidget = QWidget()
layout = QHBoxLayout()
subWidget.setLayout(layout)
self.btn_segm = QPushButton("Segment")
self.btn_segm.setShortcut("Ctrl+S")
self.buttonErrors = QPushButton("ErrorBars")
self.buttonErrors.setShortcut("Ctrl+R")
self.buttonBayesian = QPushButton("Bayesian")
self.buttonBayesian.setShortcut("Ctrl+Y")
self.btn_segm.setToolTip("Runs the segmentations according to the selected parameters (Ctrl+S)")
self.buttonErrors.setToolTip("Runs the error bars according to the selected parameters (Ctrl+R)")
self.buttonBayesian.setToolTip("Runs the Bayesian analyses according to the selected parameters (Ctrl+Y)")
self.buttonErrors.clicked.connect(self.run_errors)
self.buttonBayesian.clicked.connect(self.run_Bayesian)
self.btn_segm.clicked.connect(self.run_segm)
layout.addWidget(self.btn_segm)
layout.addWidget(self.buttonErrors)
layout.addWidget(self.buttonBayesian)
self.generalLayout.addWidget(subWidget,self.current_line,3)
def _createExitButton(self):
"""Create an exit button"""
self.exit = QPushButton("Exit")
self.exit.setToolTip("Closes the GUI and its dependencies (Ctrl+Shift+E)")
self.exit.setShortcut("Ctrl+Shift+E")
self.exit.clicked.connect(self.closing_button)
self.generalLayout.addWidget(self.exit,self.current_line,3)
self.current_line += 2
def closing_button(self):
try:
self.generalLayout.removeWidget(self.GraphRunPlot)
self.generalLayout.removeWidget(self.GraphTracePlot)
self.generalLayout.removeWidget(self.GraphCornerPlot)
self.GraphRunPlot.deleteLater()
self.GraphTracePlot.deleteLater()
self.GraphCornerPlot.deleteLater()
self.GraphRunPlot = None
self.GraphTracePlot = None
self.GraphCornerPlot = None
del self.GraphRunPlot
del self.GraphTracePlot
del self.GraphCornerPlot
except: pass
self.close()
def _createExtractDock(self):
"""Create the dock to enter a line and the buttons to extract, load and, browse the origin of the acquisition"""
subWidget = QWidget()
msg_extract = QLabel("Path: ")
source = QLineEdit()
self.btn_extr = QPushButton("Extract")
self.btn_extr.setShortcut("Ctrl+E")
self.btn_load = QPushButton("Load")
self.btn_load.setShortcut("Ctrl+L")
btn_browse = QPushButton("Browse")
btn_browse.setShortcut("Ctrl+B")
self.btn_extr.setToolTip("Extracts the relevant information from a folder containing .dcm files (Ctrl+E)")
self.btn_load.setToolTip("Loads the selected .pkl file (Ctrl+L)")
btn_browse.setToolTip("Opens a local browser to select a file (Ctrl+B)")
self.btn_extr.clicked.connect(partial(self.extract_button,source))
self.btn_load.clicked.connect(partial(self.load_button,source))
btn_browse.clicked.connect(partial(self.browse_button_file,source))
layout = QHBoxLayout()
subWidget.setLayout(layout)
layout.addWidget(btn_browse)
layout.addWidget(self.btn_extr)
layout.addWidget(self.btn_load)
self.generalLayout.addWidget(msg_extract,self.current_line,0)
self.generalLayout.addWidget(source,self.current_line,1)
self.generalLayout.addWidget(subWidget,self.current_line,2)
def _createSavingDock(self):
"""Create a button and a dock to save the image directly (removed)"""
subWidget1 = QWidget()
subWidget2 = QWidget()
layout1 = QHBoxLayout()
layout2 = QHBoxLayout()
subWidget1.setLayout(layout1)
subWidget2.setLayout(layout2)
self.btn_param = QPushButton("Parameters")
self.btn_param.setShortcut("Ctrl+P")
self.btn_param.setToolTip("Opens a window to select the paremeters used for segmentations, error bars, and Bayesian analyses (Ctrl+P)")
self.btn_param.clicked.connect(self.open_parameters)
self.btn = QPushButton("Info")
self.btn.setShortcut("Ctrl+I")
self.btn.clicked.connect(self.on_button_clicked_infos)
self.btn.setToolTip("Displays the infos of the current loaded acquisition (Ctrl+I)")
path = QLineEdit()
path_name = QLineEdit()
path.setText("")
btn_export = QPushButton("Export")
btn_export.setToolTip("Opens an window to decide what to export (Ctrl+T)")
btn_export.clicked.connect(self.open_export)
btn_export.setShortcut("Ctrl+T")
layout1.addWidget(path)
layout1.addWidget(path_name)
layout2.addWidget(btn_export)
layout2.addWidget(self.btn)
layout2.addWidget(self.btn_param)
self.generalLayout.addWidget(subWidget2,self.current_line,2)
def _createImageDisplay(self):
"""Create the docks for the 2D images to be shown"""
self.showFocus = False
self.showSubImage = False
self.showLog = False
self.showSuperpose = False
msg_Image = QLabel("View: ")
msg_Axial = QLabel("Axial")
msg_Sagittal = QLabel("Sagittal")
msg_Coronal = QLabel("Coronal")
self.axial = MplCanvas(self)
self.sagittal = MplCanvas(self)
self.coronal = MplCanvas(self)
self.axial_cid = self.axial.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.axial))
self.sagittal_cid = self.sagittal.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.sagittal))
self.coronal_cid = self.coronal.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.coronal))
self.axial_cod = self.axial.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.axial))
self.sagittal_cod = self.sagittal.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.sagittal))
self.coronal_cod = self.coronal.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.coronal))
try:
self.axial.axes.pcolormesh(self.Image.Image[0,0,:,:])
self.sagittal.axes.pcolormesh(self.Image.Image[0,:,0,:])
self.coronal.axes.pcolormesh(self.Image.Image[0,:,:,0])
except:
self.axialGraph = self.axial.axes.pcolormesh(np.zeros((100,100)))
self.sagittal.axes.pcolormesh(np.zeros((100,100)))
self.coronal.axes.pcolormesh(np.zeros((100,100)))
try:
if self.first_pass:
self.displayImageLine = self.current_line+2
except: pass
self.axial.setMinimumSize(size_Image,size_Image)
self.coronal.setMinimumSize(size_Image,size_Image)
self.sagittal.setMinimumSize(size_Image,size_Image)
self.generalLayout.addWidget(msg_Image,self.displayImageLine,0)
self.generalLayout.addWidget(msg_Axial,self.displayImageLine-1,1)
self.generalLayout.addWidget(msg_Sagittal,self.displayImageLine-1,3)
self.generalLayout.addWidget(msg_Coronal,self.displayImageLine-1,2)
self.generalLayout.addWidget(self.axial,self.displayImageLine,1)
self.generalLayout.addWidget(self.sagittal,self.displayImageLine,3)
self.generalLayout.addWidget(self.coronal,self.displayImageLine,2)
try:
if self.first_pass == True:
self.current_line += 3
self.first_pass = False
except: pass
def _createImageDisplayType(self):
"""Create the button for the combo box of the images\nAlso create the combo box for the choice of the result"""
subWidget = QWidget()
layout = QHBoxLayout()
subWidget.setLayout(layout)
self.ImageViewCombo = QComboBox()
self.view = "Slice"
self.view_range = "All"
self.ImageViewCombo.addItem("Slice")
self.ImageViewCombo.addItem("Flat")
self.ImageViewCombo.addItem("Sub. Slice")
self.ImageViewCombo.addItem("Sub. Flat")
self.ImageViewCombo.addItem("Segm. Slice")
self.ImageViewCombo.addItem("Segm. Flat")
self.ImageViewCombo.addItem("Segm. Sub. Slice")
self.ImageViewCombo.addItem("Segm. Sub. Flat")
self.ImageViewCombo.activated[str].connect(self.combo_box_changed)
self.ResultViewCombo = QComboBox()
self.resultView = "TAC"
self.ResultViewCombo.addItem("TAC")
self.ResultViewCombo.addItem("TAC Total")
self.ResultViewCombo.addItem("TAC Cumulative")
self.ResultViewCombo.addItem("TAC Cumulative Total")
self.ResultViewCombo.addItem("TAC Slice")
self.ResultViewCombo.addItem("Dice")
self.ResultViewCombo.addItem("Jaccard")
self.ResultViewCombo.addItem("Energy")
self.ResultViewCombo.addItem("Mus")
self.ResultViewCombo.addItem("Factor f")
self.ResultViewCombo.addItem("Bayesian")
self.ResultViewCombo.addItem("Center of Mass")
self.ResultViewCombo.addItem("Moments")
self.ResultViewCombo.addItem("Ratio TAC/Error")
self.ResultViewCombo.activated[str].connect(self.combo_box_result_changed)
self.ResultImageTypeCombo = QComboBox()
self.resultImageType = "Array: Base Image"
self.ResultImageTypeCombo.addItem("Array: Base Image")
self.ResultImageTypeCombo.addItem("Physical: Base Image")
self.ResultImageTypeCombo.addItem("Array: CT")
self.ResultImageTypeCombo.addItem("Physical: CT")
self.ResultImageTypeCombo.addItem("Physical: Combined")
self.ResultImageTypeCombo.activated[str].connect(self.combo_box_ImageType_changed)
layout.addWidget(self.ImageViewCombo)
layout.addWidget(self.ResultViewCombo)
layout.addWidget(self.ResultImageTypeCombo)
self.generalLayout.addWidget(subWidget,self.current_line,1)
self.current_line += 1
def _createImageDisplayBars(self):
"""Create the sliders for the 2D images, the 1D images and the TAC."""
try:
self.generalLayout.removeWidget(self.slider_widget)
self.slider_widget.setParent(None)
except:
pass
sizeText = 30
self.slider_widget = QWidget()
subWidget = QWidget()
layout = QGridLayout()
sublayout = QGridLayout()
self.slider_widget.setLayout(layout)
subWidget.setLayout(sublayout)
self.sliderAcq = QSlider(Qt.Horizontal)
self.sliderAxial = QSlider(Qt.Horizontal)
self.sliderSagittal = QSlider(Qt.Horizontal)
self.sliderCoronal = QSlider(Qt.Horizontal)
self.sliderSegm = QSlider(Qt.Horizontal)
self.sliderSegmStats = QSlider(Qt.Horizontal)
self.sliderBayesian = QSlider(Qt.Horizontal)
self.sliderFitted = QSlider(Qt.Horizontal)
try:
self.sliderAcq.setMinimum(0);self.sliderAcq.setMaximum(self.Image.nb_acq-1)
self.sliderAxial.setMinimum(0);self.sliderAxial.setMaximum(self.Image.nb_slice-1)
self.sliderSagittal.setMinimum(0);self.sliderSagittal.setMaximum(self.Image.width-1)
self.sliderCoronal.setMinimum(0);self.sliderCoronal.setMaximum(self.Image.length-1)
self.sliderSegm.setMinimum(-1);self.sliderSegm.setMaximum(self.Image.voi_counter-1)
self.sliderSegmStats.setMinimum(-1);self.sliderSegmStats.setMaximum(self.Image.voi_statistics_counter-1)
try:
self.sliderBayesian.setMinimum(-1);self.sliderBayesian.setMaximum(self.Image.bayesian_results_avg.shape[1]-1)
except: pass
try:
self.sliderFitted.setMinimum(-1);self.sliderFitted.setMaximum(self.Image.bayesian_results_avg.shape[0]-1)
except:
self.sliderFitted.setMinimum(-1);self.sliderFitted.setMaximum(-1)
except:
pass
self.sliderSegm.setValue(-1)
self.sliderSegmStats.setValue(-1)
self.sliderBayesian.setValue(-1)
self.sliderFitted.setValue(-1)
self.sliderAcq.setTickPosition(QSlider.TicksBothSides)
self.sliderAxial.setTickPosition(QSlider.TicksBothSides)
self.sliderSagittal.setTickPosition(QSlider.TicksBothSides)
self.sliderCoronal.setTickPosition(QSlider.TicksBothSides)
self.sliderSegm.setTickPosition(QSlider.TicksBothSides)
self.sliderSegmStats.setTickPosition(QSlider.TicksBothSides)
self.sliderBayesian.setTickPosition(QSlider.TicksBothSides)
self.sliderFitted.setTickPosition(QSlider.TicksBothSides)
self.sliderAcq.setSingleStep(1)
self.sliderAxial.setSingleStep(1)
self.sliderSagittal.setSingleStep(1)
self.sliderCoronal.setSingleStep(1)
self.sliderSegm.setSingleStep(1)
self.sliderSegmStats.setSingleStep(1)
self.sliderBayesian.setSingleStep(1)
self.sliderFitted.setSingleStep(1)
layout.addWidget(self.sliderAcq,0,1)
layout.addWidget(self.sliderAxial,1,1)
layout.addWidget(self.sliderSagittal,3,1)
layout.addWidget(self.sliderCoronal,2,1)
self.AcqValueHeader = QLabel("Acq:")
self.AxialValueHeader = QLabel("Ax:")
self.SagittalValueHeader = QLabel("Sag:")
self.CoronalValueHeader = QLabel("Cor:")
self.SegmValueHeader = QLabel("Segm:")
SegmStatsValueHeader = QLabel("Segm. Errors:")
BayesianValueHeader = QLabel("Bay. Values:")
FittedValueHeader = QLabel("Fit Bay.:")
self.checkBoxMsgSubImage = QLabel("Sub Image:")
self.checkBoxMsgFocus = QLabel("Focus:")
self.checkBoxMsgSuperpose = QLabel("Sup:")
self.sliderAcqValue = QLineEdit()
self.sliderAxialValue = QLineEdit()
self.sliderSagittalValue = QLineEdit()
self.sliderCoronalValue = QLineEdit()
self.sliderSegmValue = QLineEdit()
self.sliderSegmStatsValue = QLineEdit()
self.sliderBayesianValue = QLineEdit()
self.sliderFittedValue = QLineEdit()
self.checkBoxFocus = QCheckBox()
self.checkBoxSubImage = QCheckBox()
self.checkBoxLog = QCheckBox()
self.checkBoxSuperpose = QCheckBox()
self.sliderAcqValue.setFixedWidth(sizeText)
self.sliderAxialValue.setFixedWidth(sizeText)
self.sliderSagittalValue.setFixedWidth(sizeText)
self.sliderCoronalValue.setFixedWidth(sizeText)
self.sliderSegmValue.setFixedWidth(sizeText)
self.sliderSegmStatsValue.setFixedWidth(sizeText)
self.sliderBayesianValue.setFixedWidth(sizeText)
self.sliderFittedValue.setFixedWidth(sizeText)
try:
self.sliderAcqValue.setText(f"{self.set_value_slider(self.sliderAcq,self.sliderAcqValue)}")
self.sliderAxialValue.setText(f"{self.set_value_slider(self.sliderAxial,self.sliderAxialValue)}")
self.sliderSagittalValue.setText(f"{self.set_value_slider(self.sliderSagittal,self.sliderSagittalValue)}")
self.sliderCoronalValue.setText(f"{self.set_value_slider(self.sliderCoronal,self.sliderCoronalValue)}")
self.sliderSegmValue.setText(f"{self.set_value_slider(self.sliderSegm,self.sliderSegmValue)}")
self.sliderSegmStatsValue.setText(f"{self.set_value_slider(self.sliderSegmStats,self.sliderSegmStatsValue)}")
self.sliderBayesianValue.setText(f"{self.set_value_slider(self.sliderBayesian,self.sliderBayesianValue)}")
self.sliderFittedValue.setText(f"{self.set_value_slider(self.sliderFitted,self.sliderFittedValue)}")
self.sliderAcqValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderAcq,self.sliderAcqValue))
self.sliderAxialValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderAxial,self.sliderAxialValue))
self.sliderSagittalValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderSagittal,self.sliderSagittalValue))
self.sliderCoronalValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderCoronal,self.sliderCoronalValue))
self.sliderSegmValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderSegm,self.sliderSegmValue))
self.sliderSegmStatsValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderSegmStats,self.sliderSegmStatsValue))
self.sliderBayesianValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderBayesian,self.sliderBayesianValue))
self.sliderFittedValue.editingFinished.connect(partial(self.set_value_line_edit,self.sliderFitted,self.sliderFittedValue))
self.sliderAcq.valueChanged.connect(partial(self.set_value_slider,self.sliderAcq,self.sliderAcqValue))
self.sliderAxial.valueChanged.connect(partial(self.set_value_slider,self.sliderAxial,self.sliderAxialValue))
self.sliderSagittal.valueChanged.connect(partial(self.set_value_slider,self.sliderSagittal,self.sliderSagittalValue))
self.sliderCoronal.valueChanged.connect(partial(self.set_value_slider,self.sliderCoronal,self.sliderCoronalValue))
self.sliderSegm.valueChanged.connect(partial(self.set_value_slider,self.sliderSegm,self.sliderSegmValue))
self.sliderSegmStats.valueChanged.connect(partial(self.set_value_slider,self.sliderSegmStats,self.sliderSegmStatsValue))
self.sliderBayesian.valueChanged.connect(partial(self.set_value_slider,self.sliderBayesian,self.sliderBayesianValue))
self.sliderFitted.valueChanged.connect(partial(self.set_value_slider,self.sliderFitted,self.sliderFittedValue))
self.checkBoxFocus.stateChanged.connect(self.set_value_focus)
self.checkBoxSubImage.stateChanged.connect(self.set_value_subImage)
self.checkBoxLog.stateChanged.connect(self.set_value_log)
self.checkBoxSuperpose.stateChanged.connect(self.set_value_superpose)
except:
pass
checkBoxMsglog = QLabel("log:")
sublayout.addWidget(self.checkBoxMsgFocus,0,0)
sublayout.addWidget(self.checkBoxFocus,0,1)
sublayout.addWidget(self.checkBoxMsgSubImage,0,2)
sublayout.addWidget(self.checkBoxSubImage,0,3)
sublayout.addWidget(checkBoxMsglog,0,4)
sublayout.addWidget(self.checkBoxLog,0,5)
sublayout.addWidget(self.checkBoxMsgSuperpose,0,6)
sublayout.addWidget(self.checkBoxSuperpose,0,7)
subWidget.setMinimumHeight(40)
subWidget.setContentsMargins(0,0,0,0)
sublayout.addWidget(self.SegmValueHeader,2,0)
sublayout.addWidget(self.sliderSegm,2,1)
sublayout.addWidget(self.sliderSegmValue,2,2)
sublayout.addWidget(SegmStatsValueHeader,3,0)
sublayout.addWidget(self.sliderSegmStats,3,1)
sublayout.addWidget(self.sliderSegmStatsValue,3,2)
sublayout.addWidget(BayesianValueHeader,4,0)
sublayout.addWidget(self.sliderFitted,4,1)
sublayout.addWidget(self.sliderFittedValue,4,2)
sublayout.addWidget(FittedValueHeader,5,0)
sublayout.addWidget(self.sliderBayesian,5,1)
sublayout.addWidget(self.sliderBayesianValue,5,2)
layout.addWidget(self.AcqValueHeader,0,0)
layout.addWidget(self.AxialValueHeader,1,0)
layout.addWidget(self.SagittalValueHeader,3,0)
layout.addWidget(self.CoronalValueHeader,2,0)
layout.addWidget(self.sliderAcqValue,0,2)
layout.addWidget(self.sliderAxialValue,1,2)
layout.addWidget(self.sliderCoronalValue,2,2)
layout.addWidget(self.sliderSagittalValue,3,2)
self.generalLayout.addWidget(subWidget,self.displayImageLine+1,3)
self.generalLayout.addWidget(self.slider_widget,self.displayImageLine+1,1)
self.slider_widget.resize(500,500)
def _createTACImage(self):
"""Create an empty image for where the TAC and the results will be"""
self.TACImage = MplCanvas(self)
self.TAC_cid = self.TACImage.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.TACImage))
self.TAC_cod = self.TACImage.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.TACImage))
self.TACImage.setMinimumSize(size_Image,size_Image)
self.base_TAC_axes()
self.generalLayout.addWidget(self.TACImage,self.current_line,2)
self.current_line += 1
def _create1DImage(self):
"""Create the dock for the 1D Image (i.e. the slices)"""
label = QLabel("Slices")
self.AxialImage1D = MplCanvas(self)
self.SagittalImage1D = MplCanvas(self)
self.CoronalImage1D = MplCanvas(self)
self.axial1D_cid = self.AxialImage1D.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.AxialImage1D))
self.sagittal1D_cid = self.SagittalImage1D.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.SagittalImage1D))
self.coronal1D_cid = self.CoronalImage1D.fig.canvas.mpl_connect('button_press_event', partial(self.onClick, which = self.CoronalImage1D))
self.axial1D_cod = self.AxialImage1D.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.AxialImage1D))
self.sagittal1D_cod = self.SagittalImage1D.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.SagittalImage1D))
self.coronal1D_cod = self.CoronalImage1D.fig.canvas.mpl_connect('scroll_event', partial(self.onRoll, which = self.CoronalImage1D))
self.AxialImage1D.setMinimumSize(size_Image,size_Image)
self.SagittalImage1D.setMinimumSize(size_Image,size_Image)
self.CoronalImage1D.setMinimumSize(size_Image,size_Image)
self.base_1D_axes()
if self.lineImage1D == -1:
self.generalLayout.addWidget(label,self.current_line,0)
self.generalLayout.addWidget(self.AxialImage1D,self.current_line,1)
self.generalLayout.addWidget(self.CoronalImage1D,self.current_line,2)
self.generalLayout.addWidget(self.SagittalImage1D,self.current_line,3)
self.lineImage1D = self.current_line
self.current_line += 1
else:
self.generalLayout.addWidget(label,self.lineImage1D,0)
self.generalLayout.addWidget(self.AxialImage1D,self.lineImage1D,1)
self.generalLayout.addWidget(self.CoronalImage1D,self.lineImage1D,2)
self.generalLayout.addWidget(self.SagittalImage1D,self.lineImage1D,3)
self.BayesianShown = False
def _createErrorMessage(self,message:str=""):
"""Create an error message and displays it"""
alert = QMessageBox()
if message =="":
alert.setText("An error occurred")
else:
alert.setText(message)
alert.exec()
def set_value_slider(self,slider:QSlider,lineedit:QLineEdit):
"""Link the slider and the lineedit to the same value"""
lineedit.setText(str(slider.value()))
self.update_all()
return slider.value()
def set_value_focus(self):
"""Switch the focus of the image when the box is checked"""
if self.checkBoxFocus.isChecked() == True:
self.showFocus = True
else:
self.showFocus = False
self.update_all()
def set_value_subImage(self):
"""Switch the subImage view of the image when the box is checked"""
if self.checkBoxSubImage.isChecked() == True:
self.showSubImage = True
else:
self.showSubImage = False
self.update_all()
def set_value_log(self):
"""Switch the log of the image when the box is checked"""
if self.checkBoxLog.isChecked() == True:
self.showLog = True
else:
self.showLog = False
self.update_all()
def set_value_superpose(self):
"""Switch the superpose of the image when the box is checked"""
if self.checkBoxSuperpose.isChecked() == True:
self.showSuperpose = True
else:
self.showSuperpose = False
self.update_all()
def set_value_line_edit(self,slider:QSlider,lineedit:QLineEdit):
"""Link the slider and the lineedit to the same value"""
try:
slider.setValue(int(lineedit.text()))
except:
slider.setValue(0)
try:
lineedit.setText(f"{int(lineedit.text())}")
except:
lineedit.setText("0")
self.update_all()
def combo_box_changed(self):
"""Change the parameters with respect to the view of the acquisition"""
self.view = self.ImageViewCombo.currentText()
if self.view in ["Slice","Flat","Segm. Slice","Segm. Flat"]:
self.view_range = "All"
else:
self.view_range = "Sub"
try:
self.update_all()
except: pass
def combo_box_result_changed(self):
"""Update the view between partial and full"""
self.resultView = self.ResultViewCombo.currentText()
try:
self.update_all()
except: pass
def combo_box_ImageType_changed(self):
"""Update the view between partial and full"""
self.resultImageType = self.ResultImageTypeCombo.currentText()
try:
self.update_all()
except: pass
def open_parameters(self):
try:
window = ParamWindow(self.parameters,self)
window.setWindowModality(Qt.ApplicationModal)
window.signalClosed.connect(self.updateRadioNuclide)
window.signalClosed.connect(self.update_all)
window.show()
except:
self._createErrorMessage("No acquisition loaded yet")
def updateRadioNuclide(self):
self.Image.radioNuclide = self.parameters._radioNuclide
def open_export(self):
"""
Opens a new window to decide what to export and what to save
"""
try:
window = ExportWindow(self.parameters,self.Image,self)
window.setWindowModality(Qt.ApplicationModal)
window.show()
except:
self._createErrorMessage()
def run_segm(self):
"""
Function to run the segmentations based on the input parameters
"""
try:
self.threadSegmentation = QThread()
self.workerSegmentation = WorkerSegmentation(Image = self.Image, parameters = self.parameters)
self.workerSegmentation.moveToThread(self.threadSegmentation)
self.threadSegmentation.started.connect(self.workerSegmentation.segment)
self.workerSegmentation.finished.connect(self.threadSegmentation.quit)
self.workerSegmentation.finished.connect(self.workerSegmentation.deleteLater)
self.threadSegmentation.finished.connect(self.threadSegmentation.deleteLater)
self.workerSegmentation.progress.connect(self.workerDisplayStatus)
self.workerSegmentation.error.connect(self._createErrorMessage)
#self.workerSegmentation.completed.connect(self.WorkerTaskDone)
self.threadSegmentation.start()
self.btn_segm.setEnabled(False)
self.threadSegmentation.finished.connect(
lambda: self.btn_segm.setEnabled(True)
)
self.workerSegmentation.finished.connect(self.update_all)
except: pass
def run_errors(self):
"""
Function to run the errors based on the input parameters
"""
if True:
self.threadErrors = QThread()
self.workerErrors = WorkerErrors(Image = self.Image, parameters = self.parameters)
self.workerErrors.moveToThread(self.threadErrors)
self.threadErrors.started.connect(self.workerErrors.errors)
self.workerErrors.finished.connect(self.threadErrors.quit)
self.workerErrors.finished.connect(self.workerErrors.deleteLater)
self.threadErrors.finished.connect(self.threadErrors.deleteLater)
self.workerErrors.progress.connect(self.workerDisplayStatus)
self.workerErrors.error.connect(self._createErrorMessage)
#self.workerErrors.completed.connect(self.WorkerTaskDone)
self.threadErrors.start()
self.buttonErrors.setEnabled(False)
self.threadErrors.finished.connect(
lambda: self.buttonErrors.setEnabled(True)
)
self.workerErrors.finished.connect(self.update_all)
else: pass
def run_Bayesian(self):
"""
Function to run the Bayesian Analyses to extract the coefficients based on the input parameters
"""
if True:
self.threadBayesian = QThread()
self.workerBayesian = WorkerBayesian(Image = self.Image, parameters = self.parameters)
self.workerBayesian.moveToThread(self.threadBayesian)
self.threadBayesian.started.connect(self.workerBayesian.bayesian)
self.workerBayesian.finished.connect(self.threadBayesian.quit)
self.workerBayesian.finished.connect(self.workerBayesian.deleteLater)
self.threadBayesian.finished.connect(self.threadBayesian.deleteLater)
self.workerBayesian.progress.connect(self.workerDisplayStatus)
self.workerBayesian.error.connect(self._createErrorMessage)
#self.workerBayesian.completed.connect(self.WorkerTaskDone)
self.threadBayesian.start()
self.buttonBayesian.setEnabled(False)
self.threadBayesian.finished.connect(
lambda: self.buttonBayesian.setEnabled(True)
)
self.workerBayesian.finished.connect(self.update_all)
else: pass
def run_noise(self):
"""
Function to add noise to the image.
For now, the resulting image will overwrite the previous (or basic) one
"""
if True:
self.threadNoise = QThread()
self.workerNoise = WorkerNoise(Image = self.Image, parameters = self.parameters)
self.workerNoise.moveToThread(self.threadNoise)
self.threadNoise.started.connect(self.workerNoise.noise)
self.workerNoise.finished.connect(self.threadNoise.quit)
self.workerNoise.finished.connect(self.workerNoise.deleteLater)
self.threadNoise.finished.connect(self.threadNoise.deleteLater)
self.workerNoise.progress.connect(self.workerDisplayStatus)
self.workerNoise.error.connect(self._createErrorMessage)
#self.workerNoise.completed.connect(self.WorkerTaskDone)
self.threadNoise.start()
self.btn_noise.setEnabled(False)
self.threadNoise.finished.connect(
lambda: self.btn_noise.setEnabled(True)
)
self.workerNoise.finished.connect(self.update_all)
else: pass
def run_deform(self):
"""
Function to deform segmentations.
"""
if True:
self.threadDeform = QThread()
self.workerDeform = WorkerDeformation(Image = self.Image, parameters = self.parameters)
self.workerDeform.moveToThread(self.threadDeform)
self.threadDeform.started.connect(self.workerDeform.deformation)
self.workerDeform.finished.connect(self.threadDeform.quit)
self.workerDeform.finished.connect(self.workerDeform.deleteLater)
self.threadDeform.finished.connect(self.threadDeform.deleteLater)
self.workerDeform.progress.connect(self.workerDisplayStatus)
self.workerDeform.error.connect(self._createErrorMessage)
#self.workerDeform.completed.connect(self.WorkerTaskDone)
self.threadDeform.start()
self.btn_deform.setEnabled(False)
self.threadDeform.finished.connect(
lambda: self.btn_deform.setEnabled(True)
)
self.workerDeform.finished.connect(self.workerDeformFinished)
self.workerDeform.finished.connect(self.update_all)
else: pass
def run_erase(self):
"""
Function to erase computations
"""
if True:
self.threadErase = QThread()
self.workerErase = WorkerErase(Image = self.Image, parameters = self.parameters)
self.workerErase.moveToThread(self.threadErase)
self.threadErase.started.connect(self.workerErase.erase)
self.workerErase.finished.connect(self.threadErase.quit)
self.workerErase.finished.connect(self.workerErase.deleteLater)
self.threadErase.finished.connect(self.threadErase.deleteLater)
self.workerErase.progress.connect(self.workerDisplayStatus)
self.workerErase.error.connect(self._createErrorMessage)
#self.workerErase.completed.connect(self.WorkerTaskDone)
self.threadErase.start()
self.btn_erase.setEnabled(False)
self.threadErase.finished.connect(
lambda: self.btn_erase.setEnabled(True)
)
self.workerErase.finished.connect(self.update_all)
else: pass
def update_all(self):
"""Main function when something is changed to update all the views"""
self.update_Result()
if self.resultView != "TAC Slice":
self.update_1D()
else:
try:
self.update_TAC_slice()
except:
pass
self.update_view()
self.update_segm()
def update_segm(self):
"""Update the segmentation and segmentation error sliders"""
self.sliderSegm.setMaximum(self.Image.voi_counter-1)
self.sliderSegmStats.setMaximum(self.Image.voi_statistics_counter-1)
try:
self.sliderFitted.setMaximum(self.Image.bayesian_results_avg.shape[0]-1)
except:
self.sliderFitted.setMaximum(-1)
self.sliderBayesian.setMaximum(self.Image.bayesian_counter-1)
def update_Result(self):
"""Update the middle image according to the type of result to be displayed"""
try: self.cb.remove()
except: pass
if self.resultView in ["TAC", "TAC Slice", "TAC Total", "TAC Cumulative", "TAC Cumulative Total"]:
self.update_TAC()
elif self.resultView == "Dice":
self.update_Dice()
elif self.resultView == "Jaccard":
self.update_Jaccard()
elif self.resultView == "Energy":
self.update_Energy_View()
elif self.resultView == "Mus":
self.update_Mus_View()
elif self.resultView == "Factor f":
self.update_FactorF_View()
elif self.resultView == "Bayesian":
try:
self.update_Bayesian(self.sliderBayesian.value())
self.update_BayesianPlots()
except: pass
elif self.resultView == "Center of Mass":
self.update_centerMass()
elif self.resultView == "Moments":
self.update_MomentSeg()
elif self.resultView == "Ratio TAC/Error":
self.update_RatioTACError()
def update_Dice(self):
"""Shows the Dice coefficients in the middle image"""
try:
try:
self.TACImage.fig.delaxes(self.axTAC)
except:
pass
self.TACImage.axes.cla()
im = self.TACImage.axes.pcolormesh(self.Image.dice_all)
self.base_coeff_axes(im)
self.TACImage.draw()
self.switch_bottom_view()
except:
pass
def update_Jaccard(self):
"""Shows the Jaccard coefficients in the middle image"""
try:
try:
self.TACImage.fig.delaxes(self.axTAC)
except:
pass
self.TACImage.axes.cla()
im = self.TACImage.axes.pcolormesh(self.Image.jaccard_all)
self.base_coeff_axes(im)
self.TACImage.draw()
self.switch_bottom_view()
except:
pass
def update_Energy_View(self):
"""Shows the Energy of the segmentations in the middle image"""
try:
try:
self.TACImage.fig.delaxes(self.axTAC)
except:
pass
self.TACImage.axes.cla()
if self.sliderSegm.value() >= 0:
self.TACImage.axes.plot(self.Image.energies[f"{self.sliderSegm.value()}"])
else:
for i in range(self.Image.voi_counter):
self.TACImage.axes.plot(self.Image.energies[f"{i}"])
self.TACImage.axes.set_title("Energy of the Segmentation");self.TACImage.axes.grid()