mosamatic2 2.0.24__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- models.py +259 -0
- mosamatic2/__init__.py +0 -0
- mosamatic2/app.py +32 -0
- mosamatic2/cli.py +50 -0
- mosamatic2/commands/__init__.py +0 -0
- mosamatic2/commands/boadockerpipeline.py +48 -0
- mosamatic2/commands/calculatemaskstatistics.py +59 -0
- mosamatic2/commands/calculatescores.py +73 -0
- mosamatic2/commands/createdicomsummary.py +61 -0
- mosamatic2/commands/createpngsfromsegmentations.py +65 -0
- mosamatic2/commands/defaultdockerpipeline.py +84 -0
- mosamatic2/commands/defaultpipeline.py +70 -0
- mosamatic2/commands/dicom2nifti.py +55 -0
- mosamatic2/commands/liveranalysispipeline.py +61 -0
- mosamatic2/commands/rescaledicomimages.py +54 -0
- mosamatic2/commands/segmentmusclefatl3tensorflow.py +55 -0
- mosamatic2/commands/selectslicefromscans.py +66 -0
- mosamatic2/commands/totalsegmentator.py +77 -0
- mosamatic2/constants.py +27 -0
- mosamatic2/core/__init__.py +0 -0
- mosamatic2/core/data/__init__.py +5 -0
- mosamatic2/core/data/dicomimage.py +27 -0
- mosamatic2/core/data/dicomimageseries.py +26 -0
- mosamatic2/core/data/dixonseries.py +22 -0
- mosamatic2/core/data/filedata.py +26 -0
- mosamatic2/core/data/multidicomimage.py +30 -0
- mosamatic2/core/data/multiniftiimage.py +26 -0
- mosamatic2/core/data/multinumpyimage.py +26 -0
- mosamatic2/core/data/niftiimage.py +13 -0
- mosamatic2/core/data/numpyimage.py +13 -0
- mosamatic2/core/managers/__init__.py +0 -0
- mosamatic2/core/managers/logmanager.py +45 -0
- mosamatic2/core/managers/logmanagerlistener.py +3 -0
- mosamatic2/core/pipelines/__init__.py +4 -0
- mosamatic2/core/pipelines/boadockerpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/boadockerpipeline/boadockerpipeline.py +70 -0
- mosamatic2/core/pipelines/defaultdockerpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/defaultdockerpipeline/defaultdockerpipeline.py +28 -0
- mosamatic2/core/pipelines/defaultpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/defaultpipeline/defaultpipeline.py +90 -0
- mosamatic2/core/pipelines/liveranalysispipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/liveranalysispipeline/liveranalysispipeline.py +48 -0
- mosamatic2/core/pipelines/pipeline.py +14 -0
- mosamatic2/core/singleton.py +9 -0
- mosamatic2/core/tasks/__init__.py +13 -0
- mosamatic2/core/tasks/applythresholdtosegmentationstask/__init__.py +0 -0
- mosamatic2/core/tasks/applythresholdtosegmentationstask/applythresholdtosegmentationstask.py +117 -0
- mosamatic2/core/tasks/calculatemaskstatisticstask/__init__.py +0 -0
- mosamatic2/core/tasks/calculatemaskstatisticstask/calculatemaskstatisticstask.py +104 -0
- mosamatic2/core/tasks/calculatescorestask/__init__.py +0 -0
- mosamatic2/core/tasks/calculatescorestask/calculatescorestask.py +152 -0
- mosamatic2/core/tasks/createdicomsummarytask/__init__.py +0 -0
- mosamatic2/core/tasks/createdicomsummarytask/createdicomsummarytask.py +88 -0
- mosamatic2/core/tasks/createpngsfromsegmentationstask/__init__.py +0 -0
- mosamatic2/core/tasks/createpngsfromsegmentationstask/createpngsfromsegmentationstask.py +101 -0
- mosamatic2/core/tasks/dicom2niftitask/__init__.py +0 -0
- mosamatic2/core/tasks/dicom2niftitask/dicom2niftitask.py +45 -0
- mosamatic2/core/tasks/rescaledicomimagestask/__init__.py +0 -0
- mosamatic2/core/tasks/rescaledicomimagestask/rescaledicomimagestask.py +64 -0
- mosamatic2/core/tasks/segmentationnifti2numpytask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentationnifti2numpytask/segmentationnifti2numpytask.py +57 -0
- mosamatic2/core/tasks/segmentationnumpy2niftitask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentationnumpy2niftitask/segmentationnumpy2niftitask.py +86 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/paramloader.py +39 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/segmentmusclefatl3tensorflowtask.py +122 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/paramloader.py +39 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/segmentmusclefatt4pytorchtask.py +128 -0
- mosamatic2/core/tasks/selectslicefromscanstask/__init__.py +0 -0
- mosamatic2/core/tasks/selectslicefromscanstask/selectslicefromscanstask.py +249 -0
- mosamatic2/core/tasks/task.py +50 -0
- mosamatic2/core/tasks/totalsegmentatortask/__init__.py +0 -0
- mosamatic2/core/tasks/totalsegmentatortask/totalsegmentatortask.py +75 -0
- mosamatic2/core/utils.py +405 -0
- mosamatic2/server.py +146 -0
- mosamatic2/ui/__init__.py +0 -0
- mosamatic2/ui/mainwindow.py +426 -0
- mosamatic2/ui/resources/VERSION +1 -0
- mosamatic2/ui/resources/icons/mosamatic2.icns +0 -0
- mosamatic2/ui/resources/icons/mosamatic2.ico +0 -0
- mosamatic2/ui/resources/icons/spinner.gif +0 -0
- mosamatic2/ui/resources/images/body-composition.jpg +0 -0
- mosamatic2/ui/settings.py +62 -0
- mosamatic2/ui/utils.py +36 -0
- mosamatic2/ui/widgets/__init__.py +0 -0
- mosamatic2/ui/widgets/dialogs/__init__.py +0 -0
- mosamatic2/ui/widgets/dialogs/dialog.py +16 -0
- mosamatic2/ui/widgets/dialogs/helpdialog.py +9 -0
- mosamatic2/ui/widgets/panels/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/defaultpanel.py +31 -0
- mosamatic2/ui/widgets/panels/logpanel.py +65 -0
- mosamatic2/ui/widgets/panels/mainpanel.py +82 -0
- mosamatic2/ui/widgets/panels/pipelines/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/pipelines/boadockerpipelinepanel.py +195 -0
- mosamatic2/ui/widgets/panels/pipelines/defaultdockerpipelinepanel.py +314 -0
- mosamatic2/ui/widgets/panels/pipelines/defaultpipelinepanel.py +302 -0
- mosamatic2/ui/widgets/panels/pipelines/liveranalysispipelinepanel.py +187 -0
- mosamatic2/ui/widgets/panels/pipelines/pipelinepanel.py +6 -0
- mosamatic2/ui/widgets/panels/settingspanel.py +16 -0
- mosamatic2/ui/widgets/panels/stackedpanel.py +22 -0
- mosamatic2/ui/widgets/panels/tasks/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/tasks/applythresholdtosegmentationstaskpanel.py +271 -0
- mosamatic2/ui/widgets/panels/tasks/calculatemaskstatisticstaskpanel.py +215 -0
- mosamatic2/ui/widgets/panels/tasks/calculatescorestaskpanel.py +238 -0
- mosamatic2/ui/widgets/panels/tasks/createdicomsummarytaskpanel.py +206 -0
- mosamatic2/ui/widgets/panels/tasks/createpngsfromsegmentationstaskpanel.py +247 -0
- mosamatic2/ui/widgets/panels/tasks/dicom2niftitaskpanel.py +183 -0
- mosamatic2/ui/widgets/panels/tasks/rescaledicomimagestaskpanel.py +184 -0
- mosamatic2/ui/widgets/panels/tasks/segmentationnifti2numpytaskpanel.py +192 -0
- mosamatic2/ui/widgets/panels/tasks/segmentationnumpy2niftitaskpanel.py +213 -0
- mosamatic2/ui/widgets/panels/tasks/segmentmusclefatl3tensorflowtaskpanel.py +216 -0
- mosamatic2/ui/widgets/panels/tasks/segmentmusclefatt4pytorchtaskpanel.py +217 -0
- mosamatic2/ui/widgets/panels/tasks/selectslicefromscanstaskpanel.py +193 -0
- mosamatic2/ui/widgets/panels/tasks/taskpanel.py +6 -0
- mosamatic2/ui/widgets/panels/tasks/totalsegmentatortaskpanel.py +195 -0
- mosamatic2/ui/widgets/panels/visualizations/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentpicker.py +96 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentviewer.py +130 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentvisualization.py +120 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/sliceselectionviewer.py +61 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/sliceselectionvisualization.py +133 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/slicetile.py +63 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/custominteractorstyle.py +80 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/sliceviewer.py +116 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/slicevisualization.py +141 -0
- mosamatic2/ui/widgets/panels/visualizations/visualization.py +6 -0
- mosamatic2/ui/widgets/splashscreen.py +101 -0
- mosamatic2/ui/worker.py +29 -0
- mosamatic2-2.0.24.dist-info/METADATA +43 -0
- mosamatic2-2.0.24.dist-info/RECORD +136 -0
- mosamatic2-2.0.24.dist-info/WHEEL +4 -0
- mosamatic2-2.0.24.dist-info/entry_points.txt +5 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from PySide6.QtWidgets import (
|
|
4
|
+
QLineEdit,
|
|
5
|
+
QCheckBox,
|
|
6
|
+
QSpinBox,
|
|
7
|
+
QHBoxLayout,
|
|
8
|
+
QVBoxLayout,
|
|
9
|
+
QFormLayout,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QFileDialog,
|
|
12
|
+
QMessageBox,
|
|
13
|
+
)
|
|
14
|
+
from PySide6.QtCore import (
|
|
15
|
+
QThread,
|
|
16
|
+
Slot,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from mosamatic2.core.managers.logmanager import LogManager
|
|
20
|
+
from mosamatic2.ui.widgets.panels.tasks.taskpanel import TaskPanel
|
|
21
|
+
from mosamatic2.ui.settings import Settings
|
|
22
|
+
from mosamatic2.ui.utils import is_macos
|
|
23
|
+
from mosamatic2.ui.worker import Worker
|
|
24
|
+
from mosamatic2.core.tasks import Dicom2NiftiTask
|
|
25
|
+
|
|
26
|
+
LOG = LogManager()
|
|
27
|
+
|
|
28
|
+
PANEL_TITLE = 'Dicom2NiftiTask'
|
|
29
|
+
PANEL_NAME = 'dicom2niftitaskpanel'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Dicom2NiftiTaskPanel(TaskPanel):
|
|
33
|
+
def __init__(self):
|
|
34
|
+
super(Dicom2NiftiTaskPanel, self).__init__()
|
|
35
|
+
self.set_title(PANEL_TITLE)
|
|
36
|
+
self._scans_dir_line_edit = None
|
|
37
|
+
self._scans_dir_select_button = None
|
|
38
|
+
self._output_dir_line_edit = None
|
|
39
|
+
self._output_dir_select_button = None
|
|
40
|
+
self._overwrite_checkbox = None
|
|
41
|
+
self._form_layout = None
|
|
42
|
+
self._run_task_button = None
|
|
43
|
+
self._settings = None
|
|
44
|
+
self._task = None
|
|
45
|
+
self._worker = None
|
|
46
|
+
self._thread = None
|
|
47
|
+
self.init_layout()
|
|
48
|
+
|
|
49
|
+
def scans_dir_line_edit(self):
|
|
50
|
+
if not self._scans_dir_line_edit:
|
|
51
|
+
self._scans_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/scans_dir'))
|
|
52
|
+
return self._scans_dir_line_edit
|
|
53
|
+
|
|
54
|
+
def scans_dir_select_button(self):
|
|
55
|
+
if not self._scans_dir_select_button:
|
|
56
|
+
self._scans_dir_select_button = QPushButton('Select')
|
|
57
|
+
self._scans_dir_select_button.clicked.connect(self.handle_scans_dir_select_button)
|
|
58
|
+
return self._scans_dir_select_button
|
|
59
|
+
|
|
60
|
+
def output_dir_line_edit(self):
|
|
61
|
+
if not self._output_dir_line_edit:
|
|
62
|
+
self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
|
|
63
|
+
return self._output_dir_line_edit
|
|
64
|
+
|
|
65
|
+
def output_dir_select_button(self):
|
|
66
|
+
if not self._output_dir_select_button:
|
|
67
|
+
self._output_dir_select_button = QPushButton('Select')
|
|
68
|
+
self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
|
|
69
|
+
return self._output_dir_select_button
|
|
70
|
+
|
|
71
|
+
def overwrite_checkbox(self):
|
|
72
|
+
if not self._overwrite_checkbox:
|
|
73
|
+
self._overwrite_checkbox = QCheckBox('')
|
|
74
|
+
self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
|
|
75
|
+
return self._overwrite_checkbox
|
|
76
|
+
|
|
77
|
+
def form_layout(self):
|
|
78
|
+
if not self._form_layout:
|
|
79
|
+
self._form_layout = QFormLayout()
|
|
80
|
+
if is_macos():
|
|
81
|
+
self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
82
|
+
return self._form_layout
|
|
83
|
+
|
|
84
|
+
def run_task_button(self):
|
|
85
|
+
if not self._run_task_button:
|
|
86
|
+
self._run_task_button = QPushButton('Run task')
|
|
87
|
+
self._run_task_button.clicked.connect(self.handle_run_task_button)
|
|
88
|
+
return self._run_task_button
|
|
89
|
+
|
|
90
|
+
def settings(self):
|
|
91
|
+
if not self._settings:
|
|
92
|
+
self._settings = Settings()
|
|
93
|
+
return self._settings
|
|
94
|
+
|
|
95
|
+
def init_layout(self):
|
|
96
|
+
scans_dir_layout = QHBoxLayout()
|
|
97
|
+
scans_dir_layout.addWidget(self.scans_dir_line_edit())
|
|
98
|
+
scans_dir_layout.addWidget(self.scans_dir_select_button())
|
|
99
|
+
output_dir_layout = QHBoxLayout()
|
|
100
|
+
output_dir_layout.addWidget(self.output_dir_line_edit())
|
|
101
|
+
output_dir_layout.addWidget(self.output_dir_select_button())
|
|
102
|
+
self.form_layout().addRow('Scans directory', scans_dir_layout)
|
|
103
|
+
self.form_layout().addRow('Output directory', output_dir_layout)
|
|
104
|
+
self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
|
|
105
|
+
layout = QVBoxLayout()
|
|
106
|
+
layout.addLayout(self.form_layout())
|
|
107
|
+
layout.addWidget(self.run_task_button())
|
|
108
|
+
self.setLayout(layout)
|
|
109
|
+
self.setObjectName(PANEL_NAME)
|
|
110
|
+
|
|
111
|
+
def handle_scans_dir_select_button(self):
|
|
112
|
+
last_directory = self.settings().get('last_directory')
|
|
113
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
114
|
+
if directory:
|
|
115
|
+
self.scans_dir_line_edit().setText(directory)
|
|
116
|
+
self.settings().set('last_directory', directory)
|
|
117
|
+
|
|
118
|
+
def handle_output_dir_select_button(self):
|
|
119
|
+
last_directory = self.settings().get('last_directory')
|
|
120
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
121
|
+
if directory:
|
|
122
|
+
self.output_dir_line_edit().setText(directory)
|
|
123
|
+
self.settings().set('last_directory', directory)
|
|
124
|
+
|
|
125
|
+
def handle_run_task_button(self):
|
|
126
|
+
errors = self.check_inputs_and_parameters()
|
|
127
|
+
if len(errors) > 0:
|
|
128
|
+
error_message = 'Following errors were encountered:\n'
|
|
129
|
+
for error in errors:
|
|
130
|
+
error_message += f' - {error}\n'
|
|
131
|
+
QMessageBox.information(self, 'Error', error_message)
|
|
132
|
+
else:
|
|
133
|
+
LOG.info('Running task...')
|
|
134
|
+
self.run_task_button().setEnabled(False)
|
|
135
|
+
self.save_inputs_and_parameters()
|
|
136
|
+
self._task = Dicom2NiftiTask(
|
|
137
|
+
inputs={'scans': self.scans_dir_line_edit().text()},
|
|
138
|
+
params=None,
|
|
139
|
+
output=self.output_dir_line_edit().text(),
|
|
140
|
+
overwrite=self.overwrite_checkbox().isChecked(),
|
|
141
|
+
)
|
|
142
|
+
self._worker = Worker(self._task)
|
|
143
|
+
self._thread = QThread()
|
|
144
|
+
self._worker.moveToThread(self._thread)
|
|
145
|
+
self._thread.started.connect(self._worker.run)
|
|
146
|
+
self._worker.progress.connect(self.handle_progress)
|
|
147
|
+
self._worker.status.connect(self.handle_status)
|
|
148
|
+
self._worker.finished.connect(self.handle_finished)
|
|
149
|
+
self._worker.finished.connect(self._thread.quit)
|
|
150
|
+
self._worker.finished.connect(self._worker.deleteLater)
|
|
151
|
+
self._thread.finished.connect(self._thread.deleteLater)
|
|
152
|
+
self._thread.start()
|
|
153
|
+
|
|
154
|
+
@Slot(int)
|
|
155
|
+
def handle_progress(self, progress):
|
|
156
|
+
LOG.info(f'Progress: {progress} / 100%')
|
|
157
|
+
|
|
158
|
+
@Slot(str)
|
|
159
|
+
def handle_status(self, status):
|
|
160
|
+
LOG.info(f'Status: {status}')
|
|
161
|
+
|
|
162
|
+
@Slot()
|
|
163
|
+
def handle_finished(self):
|
|
164
|
+
self.run_task_button().setEnabled(True)
|
|
165
|
+
|
|
166
|
+
# HELPERS
|
|
167
|
+
|
|
168
|
+
def check_inputs_and_parameters(self):
|
|
169
|
+
errors = []
|
|
170
|
+
if self.scans_dir_line_edit().text() == '':
|
|
171
|
+
errors.append('Empty scans directory path')
|
|
172
|
+
if not os.path.isdir(self.scans_dir_line_edit().text()):
|
|
173
|
+
errors.append('Scans directory does not exist')
|
|
174
|
+
if self.output_dir_line_edit().text() == '':
|
|
175
|
+
errors.append('Empty output directory path')
|
|
176
|
+
if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
|
|
177
|
+
errors.append('Output directory exists but overwrite=False. Please remove output directory first')
|
|
178
|
+
return errors
|
|
179
|
+
|
|
180
|
+
def save_inputs_and_parameters(self):
|
|
181
|
+
self.settings().set(f'{PANEL_NAME}/scans_dir', self.scans_dir_line_edit().text())
|
|
182
|
+
self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
|
|
183
|
+
self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from PySide6.QtWidgets import (
|
|
4
|
+
QLineEdit,
|
|
5
|
+
QCheckBox,
|
|
6
|
+
QSpinBox,
|
|
7
|
+
QHBoxLayout,
|
|
8
|
+
QVBoxLayout,
|
|
9
|
+
QFormLayout,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QFileDialog,
|
|
12
|
+
QMessageBox,
|
|
13
|
+
)
|
|
14
|
+
from PySide6.QtCore import (
|
|
15
|
+
QThread,
|
|
16
|
+
Slot,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from mosamatic2.core.managers.logmanager import LogManager
|
|
20
|
+
from mosamatic2.ui.widgets.panels.tasks.taskpanel import TaskPanel
|
|
21
|
+
from mosamatic2.ui.settings import Settings
|
|
22
|
+
from mosamatic2.ui.utils import is_macos
|
|
23
|
+
from mosamatic2.ui.worker import Worker
|
|
24
|
+
from mosamatic2.core.tasks import RescaleDicomImagesTask
|
|
25
|
+
|
|
26
|
+
LOG = LogManager()
|
|
27
|
+
|
|
28
|
+
PANEL_TITLE = 'RescaleDicomImagesTask'
|
|
29
|
+
PANEL_NAME = 'rescaledicomfilestaskpanel'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class RescaleDicomImagesTaskPanel(TaskPanel):
|
|
33
|
+
def __init__(self):
|
|
34
|
+
super(RescaleDicomImagesTaskPanel, self).__init__()
|
|
35
|
+
self.set_title(PANEL_TITLE)
|
|
36
|
+
self._images_dir_line_edit = None
|
|
37
|
+
self._images_dir_select_button = None
|
|
38
|
+
self._output_dir_line_edit = None
|
|
39
|
+
self._output_dir_select_button = None
|
|
40
|
+
self._overwrite_checkbox = None
|
|
41
|
+
self._form_layout = None
|
|
42
|
+
self._run_task_button = None
|
|
43
|
+
self._settings = None
|
|
44
|
+
self._task = None
|
|
45
|
+
self._worker = None
|
|
46
|
+
self._thread = None
|
|
47
|
+
self.init_layout()
|
|
48
|
+
|
|
49
|
+
def images_dir_line_edit(self):
|
|
50
|
+
if not self._images_dir_line_edit:
|
|
51
|
+
self._images_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/images_dir'))
|
|
52
|
+
return self._images_dir_line_edit
|
|
53
|
+
|
|
54
|
+
def images_dir_select_button(self):
|
|
55
|
+
if not self._images_dir_select_button:
|
|
56
|
+
self._images_dir_select_button = QPushButton('Select')
|
|
57
|
+
self._images_dir_select_button.clicked.connect(self.handle_images_dir_select_button)
|
|
58
|
+
return self._images_dir_select_button
|
|
59
|
+
|
|
60
|
+
def output_dir_line_edit(self):
|
|
61
|
+
if not self._output_dir_line_edit:
|
|
62
|
+
self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
|
|
63
|
+
return self._output_dir_line_edit
|
|
64
|
+
|
|
65
|
+
def output_dir_select_button(self):
|
|
66
|
+
if not self._output_dir_select_button:
|
|
67
|
+
self._output_dir_select_button = QPushButton('Select')
|
|
68
|
+
self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
|
|
69
|
+
return self._output_dir_select_button
|
|
70
|
+
|
|
71
|
+
def overwrite_checkbox(self):
|
|
72
|
+
if not self._overwrite_checkbox:
|
|
73
|
+
self._overwrite_checkbox = QCheckBox('')
|
|
74
|
+
self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
|
|
75
|
+
return self._overwrite_checkbox
|
|
76
|
+
|
|
77
|
+
def form_layout(self):
|
|
78
|
+
if not self._form_layout:
|
|
79
|
+
self._form_layout = QFormLayout()
|
|
80
|
+
if is_macos():
|
|
81
|
+
self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
82
|
+
return self._form_layout
|
|
83
|
+
|
|
84
|
+
def run_task_button(self):
|
|
85
|
+
if not self._run_task_button:
|
|
86
|
+
self._run_task_button = QPushButton('Run task')
|
|
87
|
+
self._run_task_button.clicked.connect(self.handle_run_task_button)
|
|
88
|
+
return self._run_task_button
|
|
89
|
+
|
|
90
|
+
def settings(self):
|
|
91
|
+
if not self._settings:
|
|
92
|
+
self._settings = Settings()
|
|
93
|
+
return self._settings
|
|
94
|
+
|
|
95
|
+
def init_layout(self):
|
|
96
|
+
images_dir_layout = QHBoxLayout()
|
|
97
|
+
images_dir_layout.addWidget(self.images_dir_line_edit())
|
|
98
|
+
images_dir_layout.addWidget(self.images_dir_select_button())
|
|
99
|
+
output_dir_layout = QHBoxLayout()
|
|
100
|
+
output_dir_layout.addWidget(self.output_dir_line_edit())
|
|
101
|
+
output_dir_layout.addWidget(self.output_dir_select_button())
|
|
102
|
+
self.form_layout().addRow('Images directory', images_dir_layout)
|
|
103
|
+
self.form_layout().addRow('Output directory', output_dir_layout)
|
|
104
|
+
self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
|
|
105
|
+
layout = QVBoxLayout()
|
|
106
|
+
layout.addLayout(self.form_layout())
|
|
107
|
+
layout.addWidget(self.run_task_button())
|
|
108
|
+
self.setLayout(layout)
|
|
109
|
+
self.setObjectName(PANEL_NAME)
|
|
110
|
+
|
|
111
|
+
def handle_images_dir_select_button(self):
|
|
112
|
+
last_directory = self.settings().get('last_directory')
|
|
113
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
114
|
+
if directory:
|
|
115
|
+
self.images_dir_line_edit().setText(directory)
|
|
116
|
+
self.settings().set('last_directory', directory)
|
|
117
|
+
|
|
118
|
+
def handle_output_dir_select_button(self):
|
|
119
|
+
last_directory = self.settings().get('last_directory')
|
|
120
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
121
|
+
if directory:
|
|
122
|
+
self.output_dir_line_edit().setText(directory)
|
|
123
|
+
self.settings().set('last_directory', directory)
|
|
124
|
+
|
|
125
|
+
def handle_run_task_button(self):
|
|
126
|
+
errors = self.check_inputs_and_parameters()
|
|
127
|
+
if len(errors) > 0:
|
|
128
|
+
error_message = 'Following errors were encountered:\n'
|
|
129
|
+
for error in errors:
|
|
130
|
+
error_message += f' - {error}\n'
|
|
131
|
+
QMessageBox.information(self, 'Error', error_message)
|
|
132
|
+
else:
|
|
133
|
+
LOG.info('Running task...')
|
|
134
|
+
self.run_task_button().setEnabled(False)
|
|
135
|
+
self.save_inputs_and_parameters()
|
|
136
|
+
self._task = RescaleDicomImagesTask(
|
|
137
|
+
inputs={'images': self.images_dir_line_edit().text()},
|
|
138
|
+
params={'target_size': 512},
|
|
139
|
+
output=self.output_dir_line_edit().text(),
|
|
140
|
+
overwrite=self.overwrite_checkbox().isChecked(),
|
|
141
|
+
)
|
|
142
|
+
self._worker = Worker(self._task)
|
|
143
|
+
self._thread = QThread()
|
|
144
|
+
self._worker.moveToThread(self._thread)
|
|
145
|
+
self._thread.started.connect(self._worker.run)
|
|
146
|
+
self._worker.progress.connect(self.handle_progress)
|
|
147
|
+
self._worker.status.connect(self.handle_status)
|
|
148
|
+
self._worker.finished.connect(self.handle_finished)
|
|
149
|
+
self._worker.finished.connect(self._thread.quit)
|
|
150
|
+
self._worker.finished.connect(self._worker.deleteLater)
|
|
151
|
+
self._thread.finished.connect(self._thread.deleteLater)
|
|
152
|
+
self._thread.start()
|
|
153
|
+
|
|
154
|
+
@Slot(int)
|
|
155
|
+
def handle_progress(self, progress):
|
|
156
|
+
LOG.info(f'Progress: {progress} / 100%')
|
|
157
|
+
|
|
158
|
+
@Slot(str)
|
|
159
|
+
def handle_status(self, status):
|
|
160
|
+
LOG.info(f'Status: {status}')
|
|
161
|
+
|
|
162
|
+
@Slot()
|
|
163
|
+
def handle_finished(self):
|
|
164
|
+
LOG.info(f'Output saved in {self._task.output()}')
|
|
165
|
+
self.run_task_button().setEnabled(True)
|
|
166
|
+
|
|
167
|
+
# HELPERS
|
|
168
|
+
|
|
169
|
+
def check_inputs_and_parameters(self):
|
|
170
|
+
errors = []
|
|
171
|
+
if self.images_dir_line_edit().text() == '':
|
|
172
|
+
errors.append('Empty images directory path')
|
|
173
|
+
if not os.path.isdir(self.images_dir_line_edit().text()):
|
|
174
|
+
errors.append('Images directory does not exist')
|
|
175
|
+
if self.output_dir_line_edit().text() == '':
|
|
176
|
+
errors.append('Empty output directory path')
|
|
177
|
+
if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
|
|
178
|
+
errors.append('Output directory exists but overwrite=False. Please remove output directory first')
|
|
179
|
+
return errors
|
|
180
|
+
|
|
181
|
+
def save_inputs_and_parameters(self):
|
|
182
|
+
self.settings().set(f'{PANEL_NAME}/images_dir', self.images_dir_line_edit().text())
|
|
183
|
+
self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
|
|
184
|
+
self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from PySide6.QtWidgets import (
|
|
4
|
+
QLineEdit,
|
|
5
|
+
QCheckBox,
|
|
6
|
+
QSpinBox,
|
|
7
|
+
QHBoxLayout,
|
|
8
|
+
QVBoxLayout,
|
|
9
|
+
QFormLayout,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QFileDialog,
|
|
12
|
+
QMessageBox,
|
|
13
|
+
)
|
|
14
|
+
from PySide6.QtCore import (
|
|
15
|
+
QThread,
|
|
16
|
+
Slot,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from mosamatic2.core.managers.logmanager import LogManager
|
|
20
|
+
from mosamatic2.ui.widgets.panels.tasks.taskpanel import TaskPanel
|
|
21
|
+
from mosamatic2.ui.settings import Settings
|
|
22
|
+
from mosamatic2.ui.utils import is_macos
|
|
23
|
+
from mosamatic2.ui.worker import Worker
|
|
24
|
+
from mosamatic2.core.tasks import SegmentationNifti2NumpyTask
|
|
25
|
+
|
|
26
|
+
LOG = LogManager()
|
|
27
|
+
|
|
28
|
+
PANEL_TITLE = 'SegmentationNifti2NumpyTask'
|
|
29
|
+
PANEL_NAME = 'segmentationnifti2numpytaskpanel'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SegmentationNifti2NumpyTaskPanel(TaskPanel):
|
|
33
|
+
def __init__(self):
|
|
34
|
+
super(SegmentationNifti2NumpyTaskPanel, self).__init__()
|
|
35
|
+
self.set_title(PANEL_TITLE)
|
|
36
|
+
self._segmentations_dir_line_edit = None
|
|
37
|
+
self._segmentations_dir_select_button = None
|
|
38
|
+
self._output_dir_line_edit = None
|
|
39
|
+
self._output_dir_select_button = None
|
|
40
|
+
self._png_checkbox = None
|
|
41
|
+
self._overwrite_checkbox = None
|
|
42
|
+
self._form_layout = None
|
|
43
|
+
self._run_task_button = None
|
|
44
|
+
self._settings = None
|
|
45
|
+
self._task = None
|
|
46
|
+
self._worker = None
|
|
47
|
+
self._thread = None
|
|
48
|
+
self.init_layout()
|
|
49
|
+
|
|
50
|
+
def segmentations_dir_line_edit(self):
|
|
51
|
+
if not self._segmentations_dir_line_edit:
|
|
52
|
+
self._segmentations_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/segmentations_dir'))
|
|
53
|
+
return self._segmentations_dir_line_edit
|
|
54
|
+
|
|
55
|
+
def segmentations_dir_select_button(self):
|
|
56
|
+
if not self._segmentations_dir_select_button:
|
|
57
|
+
self._segmentations_dir_select_button = QPushButton('Select')
|
|
58
|
+
self._segmentations_dir_select_button.clicked.connect(self.handle_segmentations_dir_select_button)
|
|
59
|
+
return self._segmentations_dir_select_button
|
|
60
|
+
|
|
61
|
+
def output_dir_line_edit(self):
|
|
62
|
+
if not self._output_dir_line_edit:
|
|
63
|
+
self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
|
|
64
|
+
return self._output_dir_line_edit
|
|
65
|
+
|
|
66
|
+
def output_dir_select_button(self):
|
|
67
|
+
if not self._output_dir_select_button:
|
|
68
|
+
self._output_dir_select_button = QPushButton('Select')
|
|
69
|
+
self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
|
|
70
|
+
return self._output_dir_select_button
|
|
71
|
+
|
|
72
|
+
def png_checkbox(self):
|
|
73
|
+
if not self._png_checkbox:
|
|
74
|
+
self._png_checkbox = QCheckBox('')
|
|
75
|
+
self._png_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/png', True))
|
|
76
|
+
return self._png_checkbox
|
|
77
|
+
|
|
78
|
+
def overwrite_checkbox(self):
|
|
79
|
+
if not self._overwrite_checkbox:
|
|
80
|
+
self._overwrite_checkbox = QCheckBox('')
|
|
81
|
+
self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
|
|
82
|
+
return self._overwrite_checkbox
|
|
83
|
+
|
|
84
|
+
def form_layout(self):
|
|
85
|
+
if not self._form_layout:
|
|
86
|
+
self._form_layout = QFormLayout()
|
|
87
|
+
if is_macos():
|
|
88
|
+
self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
89
|
+
return self._form_layout
|
|
90
|
+
|
|
91
|
+
def run_task_button(self):
|
|
92
|
+
if not self._run_task_button:
|
|
93
|
+
self._run_task_button = QPushButton('Run task')
|
|
94
|
+
self._run_task_button.clicked.connect(self.handle_run_task_button)
|
|
95
|
+
return self._run_task_button
|
|
96
|
+
|
|
97
|
+
def settings(self):
|
|
98
|
+
if not self._settings:
|
|
99
|
+
self._settings = Settings()
|
|
100
|
+
return self._settings
|
|
101
|
+
|
|
102
|
+
def init_layout(self):
|
|
103
|
+
segmentations_dir_layout = QHBoxLayout()
|
|
104
|
+
segmentations_dir_layout.addWidget(self.segmentations_dir_line_edit())
|
|
105
|
+
segmentations_dir_layout.addWidget(self.segmentations_dir_select_button())
|
|
106
|
+
output_dir_layout = QHBoxLayout()
|
|
107
|
+
output_dir_layout.addWidget(self.output_dir_line_edit())
|
|
108
|
+
output_dir_layout.addWidget(self.output_dir_select_button())
|
|
109
|
+
self.form_layout().addRow('Segmentations directory', segmentations_dir_layout)
|
|
110
|
+
self.form_layout().addRow('Output directory', output_dir_layout)
|
|
111
|
+
self.form_layout().addRow('PNG', self.png_checkbox())
|
|
112
|
+
self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
|
|
113
|
+
layout = QVBoxLayout()
|
|
114
|
+
layout.addLayout(self.form_layout())
|
|
115
|
+
layout.addWidget(self.run_task_button())
|
|
116
|
+
self.setLayout(layout)
|
|
117
|
+
self.setObjectName(PANEL_NAME)
|
|
118
|
+
|
|
119
|
+
def handle_segmentations_dir_select_button(self):
|
|
120
|
+
last_directory = self.settings().get('last_directory')
|
|
121
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
122
|
+
if directory:
|
|
123
|
+
self.segmentations_dir_line_edit().setText(directory)
|
|
124
|
+
self.settings().set('last_directory', directory)
|
|
125
|
+
|
|
126
|
+
def handle_output_dir_select_button(self):
|
|
127
|
+
last_directory = self.settings().get('last_directory')
|
|
128
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
129
|
+
if directory:
|
|
130
|
+
self.output_dir_line_edit().setText(directory)
|
|
131
|
+
self.settings().set('last_directory', directory)
|
|
132
|
+
|
|
133
|
+
def handle_run_task_button(self):
|
|
134
|
+
errors = self.check_inputs_and_parameters()
|
|
135
|
+
if len(errors) > 0:
|
|
136
|
+
error_message = 'Following errors were encountered:\n'
|
|
137
|
+
for error in errors:
|
|
138
|
+
error_message += f' - {error}\n'
|
|
139
|
+
QMessageBox.information(self, 'Error', error_message)
|
|
140
|
+
else:
|
|
141
|
+
LOG.info('Running task...')
|
|
142
|
+
self.run_task_button().setEnabled(False)
|
|
143
|
+
self.save_inputs_and_parameters()
|
|
144
|
+
self._task = SegmentationNifti2NumpyTask(
|
|
145
|
+
inputs={'segmentations': self.segmentations_dir_line_edit().text()},
|
|
146
|
+
params={'png': self.png_checkbox().isChecked()},
|
|
147
|
+
output=self.output_dir_line_edit().text(),
|
|
148
|
+
overwrite=self.overwrite_checkbox().isChecked(),
|
|
149
|
+
)
|
|
150
|
+
self._worker = Worker(self._task)
|
|
151
|
+
self._thread = QThread()
|
|
152
|
+
self._worker.moveToThread(self._thread)
|
|
153
|
+
self._thread.started.connect(self._worker.run)
|
|
154
|
+
self._worker.progress.connect(self.handle_progress)
|
|
155
|
+
self._worker.status.connect(self.handle_status)
|
|
156
|
+
self._worker.finished.connect(self.handle_finished)
|
|
157
|
+
self._worker.finished.connect(self._thread.quit)
|
|
158
|
+
self._worker.finished.connect(self._worker.deleteLater)
|
|
159
|
+
self._thread.finished.connect(self._thread.deleteLater)
|
|
160
|
+
self._thread.start()
|
|
161
|
+
|
|
162
|
+
@Slot(int)
|
|
163
|
+
def handle_progress(self, progress):
|
|
164
|
+
LOG.info(f'Progress: {progress} / 100%')
|
|
165
|
+
|
|
166
|
+
@Slot(str)
|
|
167
|
+
def handle_status(self, status):
|
|
168
|
+
LOG.info(f'Status: {status}')
|
|
169
|
+
|
|
170
|
+
@Slot()
|
|
171
|
+
def handle_finished(self):
|
|
172
|
+
self.run_task_button().setEnabled(True)
|
|
173
|
+
|
|
174
|
+
# HELPERS
|
|
175
|
+
|
|
176
|
+
def check_inputs_and_parameters(self):
|
|
177
|
+
errors = []
|
|
178
|
+
if self.segmentations_dir_line_edit().text() == '':
|
|
179
|
+
errors.append('Empty segmentations directory path')
|
|
180
|
+
if not os.path.isdir(self.segmentations_dir_line_edit().text()):
|
|
181
|
+
errors.append('Segmentations directory does not exist')
|
|
182
|
+
if self.output_dir_line_edit().text() == '':
|
|
183
|
+
errors.append('Empty output directory path')
|
|
184
|
+
if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
|
|
185
|
+
errors.append('Output directory exists but overwrite=False. Please remove output directory first')
|
|
186
|
+
return errors
|
|
187
|
+
|
|
188
|
+
def save_inputs_and_parameters(self):
|
|
189
|
+
self.settings().set(f'{PANEL_NAME}/segmentations_dir', self.segmentations_dir_line_edit().text())
|
|
190
|
+
self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
|
|
191
|
+
self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
|
|
192
|
+
self.settings().set(f'{PANEL_NAME}/png', self.png_checkbox().isChecked())
|