Skip to content

Commit

Permalink
Merge branch 'T26896-TractSeg'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterneher committed Dec 6, 2019
2 parents 3ff5d37 + 5342894 commit 5b33778
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<item row="0" column="0" rowspan="3">
<widget class="QToolBox" name="toolBox">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
Expand Down Expand Up @@ -1034,7 +1034,7 @@
<item row="0" column="1">
<widget class="QSpinBox" name="m_MaxTwistBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Max. fiber twist per step (in degree)</string>
</property>
<property name="minimum">
<number>0</number>
Expand All @@ -1053,7 +1053,7 @@
<item row="0" column="0">
<widget class="QSpinBox" name="m_MinTwistBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Min. fiber twist per step (in degree)</string>
</property>
<property name="minimum">
<number>0</number>
Expand Down Expand Up @@ -1115,7 +1115,7 @@
<item row="0" column="0">
<widget class="QSpinBox" name="m_StepSizeMinBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Min. distance between fiducials (in mm)</string>
</property>
<property name="minimum">
<number>1</number>
Expand All @@ -1134,7 +1134,7 @@
<item row="0" column="1">
<widget class="QSpinBox" name="m_StepSizeMaxBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Max. distance between fiducials (in mm)</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -1175,7 +1175,7 @@
<item row="1" column="1">
<widget class="QSpinBox" name="m_NumBundlesBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Number of generated bundles</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -1234,7 +1234,7 @@
<item row="0" column="0">
<widget class="QSpinBox" name="m_CurvyMinBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Min. rotation between steps (in degree)</string>
</property>
<property name="minimum">
<number>1</number>
Expand All @@ -1253,7 +1253,7 @@
<item row="0" column="1">
<widget class="QSpinBox" name="m_CurvyMaxBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Max. rotation between steps (in degree)</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -1415,7 +1415,7 @@
<item row="0" column="0">
<widget class="QSpinBox" name="m_SizeMinBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Bundle radius</string>
</property>
<property name="minimum">
<number>1</number>
Expand All @@ -1434,7 +1434,7 @@
<item row="0" column="1">
<widget class="QSpinBox" name="m_SizeMaxBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>Bundle radius</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -1477,7 +1477,7 @@
<item row="0" column="1">
<widget class="QSpinBox" name="m_MaxDensityBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Max. fibers per cm&lt;span style=&quot; vertical-align:super;&quot;&gt;2&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>1</number>
Expand All @@ -1496,7 +1496,7 @@
<item row="0" column="0">
<widget class="QSpinBox" name="m_MinDensityBox">
<property name="toolTip">
<string>Specify number of fibers to generate for the selected bundle.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Min. fibers per cm&lt;span style=&quot; vertical-align:super;&quot;&gt;2&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>1</number>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

data = sitk.GetArrayFromImage(in_image)
data = np.nan_to_num(data)

swapaxes = False
if data.shape != (sx, sy, sz):
print("Swapping axes!")
data = np.swapaxes(data, 0, 2)
swapaxes = True
data = np.swapaxes(data, 0, 2)
swapaxes = True

affine = np.zeros((4, 4))
affine[0, 0] = in_image.GetDirection()[0] * in_image.GetSpacing()[0]
Expand All @@ -39,13 +38,11 @@
print('threshold', threshold)

seg = run_tractseg(data=data, output_type=output_type, input_type="peaks", verbose=verbose, get_probs=get_probs,
dropout_sampling=dropout_sampling, threshold=threshold, postprocess=False)
dropout_sampling=dropout_sampling, threshold=threshold, postprocess=False, nr_cpus=1)

# bla = nib.Nifti1Image(seg, affine)
# nib.save(bla, '/home/neher/test.nii.gz')
if swapaxes:
print("Swapping axes back!")
seg = np.swapaxes(seg, 0, 2)
# bla = nib.Nifti1Image(seg, affine)
# nib.save(bla, '/home/neher/test.nii.gz')
seg = np.swapaxes(seg, 0, 2)

print('Output shape: ' + str(seg.shape))
if output_type == "tract_segmentation":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void QmitkTractSegView::Start()

// get python script as string
QString data;
QString fileName(":/QmitkDiffusionImaging/tractseg.py");
QString fileName(":/QmitkDiffusionPython/tractseg.py");
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly)) {
qDebug()<<"filenot opened"<<endl;
Expand All @@ -125,6 +125,9 @@ void QmitkTractSegView::Start()
}
file.close();

if (data.size()==0)
mitkThrow() << fileName << " could not be read!";

us::ModuleContext* context = us::GetModuleContext();
us::ServiceReference<mitk::IPythonService> m_PythonServiceRef = context->GetServiceReference<mitk::IPythonService>();
mitk::IPythonService* m_PythonService = dynamic_cast<mitk::IPythonService*> ( context->GetService<mitk::IPythonService>(m_PythonServiceRef) );
Expand Down Expand Up @@ -198,6 +201,7 @@ void QmitkTractSegView::Start()
// check for errors
if(!m_PythonService->GetVariable("error_string").empty())
{
mitk::IPythonService::ForceLoadModule();
QMessageBox::warning(nullptr, "Error", QString(m_PythonService->GetVariable("error_string").c_str()), QMessageBox::Ok);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion PythonRequirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SimpleITK
dipy
sklearn
https://github.com/MIC-DKFZ/batchgenerators/archive/v0.19.5.zip
https://github.com/MIC-DKFZ/TractSeg/archive/v2.1.1.zip
https://github.com/MIC-DKFZ/TractSeg/archive/master.zip
https://github.com/MIC-DKFZ/HD-BET/archive/master.zip
torch
torchvision
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Automatically generated random fiber configuration for Fiberfox simulations.


## Building MITK Diffusion from source
* Install [Qt](https://www.qt.io/ Qt) on your system (>= 5.11.1).
* Install [Qt](https://www.qt.io/) on your system (>= 5.12.6).
* Clone MITK from [github](https://github.com/MIC-DKFZ/MITK-Diffusion.git) using [Git version control](https://git-scm.com/).
* Clone MITK Diffusion from [github](https://github.com/MITK/MITK.git).
* Configure the MITK Superbuild using [CMake](https://cmake.org/) (>= 3.14.5).
Expand Down

0 comments on commit 5b33778

Please sign in to comment.