Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDemonsRegistrationView.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "itkRegularStepGradientDescentOptimizer.h"
19 #include "mitkITKImageImport.h"
20 #include "mitkProgressBar.h"
21 #include "ui_QmitkDemonsRegistrationViewControls.h"
22 #include <mitkImageCast.h>
24 #include <mitkRenderingManager.h>
25 #include <qfiledialog.h>
26 #include <qmessagebox.h>
27 #include <qvalidator.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 
32  : QWidget(parent, f),
33  m_FixedNode(nullptr),
34  m_MovingNode(nullptr),
35  m_ResultImage(nullptr),
36  m_ResultDeformationField(nullptr)
37 {
38  m_Controls.setupUi(parent);
39 
40  QValidator *validatorHistogramLevels = new QIntValidator(1, 20000000, this);
41  m_Controls.m_NumberOfHistogramLevels->setValidator(validatorHistogramLevels);
42 
43  QValidator *validatorMatchPoints = new QIntValidator(1, 20000000, this);
44  m_Controls.m_NumberOfMatchPoints->setValidator(validatorMatchPoints);
45 
46  QValidator *validatorIterations = new QIntValidator(1, 20000000, this);
47  m_Controls.m_Iterations->setValidator(validatorIterations);
48 
49  QValidator *validatorStandardDeviation = new QDoubleValidator(0, 20000000, 2, this);
50  m_Controls.m_StandardDeviation->setValidator(validatorStandardDeviation);
51 }
52 
54 {
55 }
56 
58 {
59  return atoi(m_Controls.m_Iterations->text().toLatin1());
60 }
61 
63 {
64  return atof(m_Controls.m_StandardDeviation->text().toLatin1());
65 }
66 
68 {
69  return m_ResultImage;
70 }
71 
73 {
75 }
76 
78 {
79  if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull())
80  {
81  mitk::Image::Pointer fimage = dynamic_cast<mitk::Image *>(m_FixedNode->GetData());
82  mitk::Image::Pointer mimage = dynamic_cast<mitk::Image *>(m_MovingNode->GetData());
83  // workaround to ensure that fimage covers a bigger region than mimage
84  mitk::Image::RegionType fimageRegion = fimage->GetLargestPossibleRegion();
85  mitk::Image::RegionType mimageRegion = mimage->GetLargestPossibleRegion();
86  if (!((fimageRegion.GetSize(0) >= mimageRegion.GetSize(0)) &&
87  (fimageRegion.GetSize(1) >= mimageRegion.GetSize(1)) && (fimageRegion.GetSize(2) >= mimageRegion.GetSize(2))))
88  {
89  QMessageBox::information(
90  nullptr, "Registration", "Fixed image must be equal or bigger in size than moving image.");
91  return;
92  }
93  if (m_Controls.m_RegistrationSelection->currentIndex() == 0)
94  {
96  registration->SetSaveDeformationField(false);
97  registration->SetSaveResult(false);
98  registration->SetReferenceImage(fimage);
99  registration->SetNumberOfIterations(atoi(m_Controls.m_Iterations->text().toLatin1()));
100  registration->SetStandardDeviation(atof(m_Controls.m_StandardDeviation->text().toLatin1()));
101  if (m_Controls.m_UseHistogramMatching->isChecked())
102  {
104  histogramMatching->SetReferenceImage(fimage);
105  histogramMatching->SetInput(mimage);
106  histogramMatching->SetNumberOfHistogramLevels(atoi(m_Controls.m_NumberOfHistogramLevels->text().toLatin1()));
107  histogramMatching->SetNumberOfMatchPoints(atoi(m_Controls.m_NumberOfMatchPoints->text().toLatin1()));
108  histogramMatching->SetThresholdAtMeanIntensity(m_Controls.m_ThresholdAtMeanIntensity->isChecked());
109  histogramMatching->Update();
110  mitk::Image::Pointer histimage = histogramMatching->GetOutput();
111  if (histimage.IsNotNull())
112  {
113  registration->SetInput(histimage);
114  }
115  else
116  {
117  registration->SetInput(mimage);
118  }
119  }
120  else
121  {
122  registration->SetInput(mimage);
123  }
124  try
125  {
126  registration->Update();
127  }
128  catch (itk::ExceptionObject &excpt)
129  {
130  QMessageBox::information(this, "Registration exception", excpt.GetDescription(), QMessageBox::Ok);
132  return;
133  }
134  m_ResultImage = registration->GetOutput();
135  typedef itk::Image<itk::Vector<float, 3>, 3> VectorImageType;
136  VectorImageType::Pointer deformationField = registration->GetDeformationField();
137  m_ResultDeformationField = mitk::ImportItkImage(deformationField)->Clone();
138  }
139  else if (m_Controls.m_RegistrationSelection->currentIndex() == 1)
140  {
142  registration->SetSaveDeformationField(false);
143  registration->SetSaveResult(false);
144  registration->SetReferenceImage(fimage);
145  registration->SetNumberOfIterations(atoi(m_Controls.m_Iterations->text().toLatin1()));
146  registration->SetStandardDeviation(atof(m_Controls.m_StandardDeviation->text().toLatin1()));
147  if (m_Controls.m_UseHistogramMatching->isChecked())
148  {
150  histogramMatching->SetReferenceImage(fimage);
151  histogramMatching->SetInput(mimage);
152  histogramMatching->SetNumberOfHistogramLevels(atoi(m_Controls.m_NumberOfHistogramLevels->text().toLatin1()));
153  histogramMatching->SetNumberOfMatchPoints(atoi(m_Controls.m_NumberOfMatchPoints->text().toLatin1()));
154  histogramMatching->SetThresholdAtMeanIntensity(m_Controls.m_ThresholdAtMeanIntensity->isChecked());
155  histogramMatching->Update();
156  mitk::Image::Pointer histimage = histogramMatching->GetOutput();
157  if (histimage.IsNotNull())
158  {
159  registration->SetInput(histimage);
160  }
161  else
162  {
163  registration->SetInput(mimage);
164  }
165  }
166  else
167  {
168  registration->SetInput(mimage);
169  }
170  try
171  {
172  registration->Update();
173  }
174  catch (itk::ExceptionObject &excpt)
175  {
176  QMessageBox::information(this, "Registration exception", excpt.GetDescription(), QMessageBox::Ok);
178  return;
179  }
180  m_ResultImage = registration->GetOutput();
181  typedef itk::Image<itk::Vector<float, 3>, 3> VectorImageType;
182  VectorImageType::Pointer deformationField = registration->GetDeformationField();
183  m_ResultDeformationField = mitk::ImportItkImage(deformationField)->Clone();
184  }
185  }
186 }
187 
189 {
190  m_FixedNode = fixedNode;
191 }
192 
194 {
195  m_MovingNode = movingNode;
196 }
197 
199 {
200  if (useHM)
201  {
202  m_Controls.numberOfHistogramLevels->setEnabled(true);
203  m_Controls.m_NumberOfHistogramLevels->setEnabled(true);
204  m_Controls.numberOfMatchPoints->setEnabled(true);
205  m_Controls.m_NumberOfMatchPoints->setEnabled(true);
206  m_Controls.thresholdAtMeanIntensity->setEnabled(true);
207  m_Controls.m_ThresholdAtMeanIntensity->setEnabled(true);
208  }
209  else
210  {
211  m_Controls.numberOfHistogramLevels->setEnabled(false);
212  m_Controls.m_NumberOfHistogramLevels->setEnabled(false);
213  m_Controls.numberOfMatchPoints->setEnabled(false);
214  m_Controls.m_NumberOfMatchPoints->setEnabled(false);
215  m_Controls.thresholdAtMeanIntensity->setEnabled(false);
216  m_Controls.m_ThresholdAtMeanIntensity->setEnabled(false);
217  }
218 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
static Pointer New()
Method for creation through the object factory.
itk::SmartPointer< Self > Pointer
static Pointer New()
Method for creation through the object factory.
Ui::QmitkDemonsRegistrationViewControls m_Controls
mitk::Image::Pointer m_ResultDeformationField
static Pointer New()
Method for creation through the object factory.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
Image::Pointer ImportItkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, const BaseGeometry *geometry=nullptr, bool update=true)
Imports an itk::Image (with a specific type) as an mitk::Image.Instantiates instance of ITKImageImpor...
itk::VectorImage< float, 3 > VectorImageType
void SetFixedNode(mitk::DataNode *fixedNode)
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
Definition: mitkImage.h:76
void SetMovingNode(mitk::DataNode *movingNode)
mitk::Image::Pointer GetResultDeformationfield()
QmitkDemonsRegistrationView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66