Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPyramidalRegistrationMethod.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 
19 
20 namespace mitk
21 {
22  PyramidalRegistrationMethod::PyramidalRegistrationMethod() : m_Observer(nullptr), m_Interpolator(0)
23  {
24  m_OptimizerParameters = OptimizerParameters::New();
25  m_TransformParameters = TransformParameters::New();
26  m_MetricParameters = MetricParameters::New();
30 
31  m_Preset = new mitk::RigidRegistrationPreset();
32 
33  bool succeed = m_Preset->LoadPreset();
34  if (!succeed)
35  {
36  std::cout << "RigidRegistrationParameters.xml is empty or does not exist. There are no presets to select."
37  << std::endl;
38  return;
39  }
40 
41  m_UseMask = false;
42  m_BlurMovingImage = true;
43  m_BlurFixedImage = true;
44  }
45 
48  {
49  if (this->GetInput())
50  {
52  }
53  }
54 
56  void PyramidalRegistrationMethod::SetInterpolator(int interpolator) { m_Interpolator = interpolator; }
58  {
59  m_ReferenceImage = fixedImage;
60  SetNthInput(1, m_ReferenceImage);
61  Modified();
62  }
63 
64  mitk::TransformParameters::Pointer PyramidalRegistrationMethod::ParseTransformParameters(
65  itk::Array<double> transformValues)
66  {
68 
69  itk::Array<double> initialParameters;
70  if (transformParameters->GetInitialParameters().size())
71  {
72  initialParameters = transformParameters->GetInitialParameters();
73  }
74  transformParameters = mitk::TransformParameters::New();
75  transformParameters->SetTransform(transformValues[0]);
76 
77  if (transformParameters->GetInitialParameters().size())
78  {
79  transformParameters->SetInitialParameters(initialParameters);
80  }
81 
82  // Set scales. Every type of transform has a different number of scales!!!
83  // TODO: Finish for al types of transform (or find a better solution)
84  itk::Array<double> scales;
85  if (transformValues[0] == mitk::TransformParameters::AFFINETRANSFORM)
86  scales.SetSize(12);
87  if (transformValues[0] == mitk::TransformParameters::TRANSLATIONTRANSFORM)
88  scales.SetSize(3);
89 
90  for (unsigned int i = 0; i < scales.size(); i++)
91  {
92  scales[i] = transformValues[i + 2];
93  }
94  transformParameters->SetScales(scales);
95  transformParameters->SetTransformInitializerOn(false);
96 
97  // Use Scales
98  if (transformValues[1] == 1)
99  {
100  transformParameters->SetUseOptimizerScales(true);
101  }
102 
103  return transformParameters;
104  }
105 
106  mitk::MetricParameters::Pointer PyramidalRegistrationMethod::ParseMetricParameters(itk::Array<double> metricValues)
107  {
109 
110  metricParameters->SetMetric(metricValues[0]);
111  metricParameters->SetComputeGradient(metricValues[1]);
112 
113  // Some things have to be checked for every metric individually
115  {
116  metricParameters->SetNumberOfHistogramBinsMutualInformationHistogram(metricValues[2]);
117  }
118 
120  {
121  metricParameters->SetSpatialSamplesMattesMutualInformation(metricValues[3]);
122  metricParameters->SetNumberOfHistogramBinsMattesMutualInformation(metricValues[4]);
123  }
124 
125  return metricParameters;
126  }
127 
128  mitk::OptimizerParameters::Pointer PyramidalRegistrationMethod::ParseOptimizerParameters(
129  itk::Array<double> optimizerValues)
130  {
132 
133  optimizerParameters->SetOptimizer(optimizerValues[0]);
134  optimizerParameters->SetMaximize(
135  optimizerValues[1]); // should be when used with maximize mutual information for example
136 
137  if (optimizerValues[0] == mitk::OptimizerParameters::GRADIENTDESCENTOPTIMIZER)
138  {
139  optimizerParameters->SetLearningRateGradientDescent(optimizerValues[2]);
140  optimizerParameters->SetNumberOfIterationsGradientDescent(optimizerValues[3]);
141  }
142 
144  {
145  cout << "use regularstepgradientdescent" << endl;
146  optimizerParameters->SetGradientMagnitudeToleranceRegularStepGradientDescent(optimizerValues[2]);
147  optimizerParameters->SetMinimumStepLengthRegularStepGradientDescent(optimizerValues[3]);
148  optimizerParameters->SetMaximumStepLengthRegularStepGradientDescent(optimizerValues[4]);
149  optimizerParameters->SetRelaxationFactorRegularStepGradientDescent(optimizerValues[5]);
150  optimizerParameters->SetNumberOfIterationsRegularStepGradientDescent(optimizerValues[6]);
151  }
152 
153  return optimizerParameters;
154  }
155 
157  {
158  m_MovingMask = movingMask;
159  SetNthInput(3, m_MovingMask);
160  Modified();
161  }
162 
164  {
165  m_FixedMask = FixedMask;
166  SetNthInput(4, m_FixedMask);
167  Modified();
168  }
169 
170 } // end namespace
void SetObserver(RigidRegistrationObserver::Pointer observer)
Class to load and save parameter presets for rigid registration.
itk::SmartPointer< Self > Pointer
bool LoadPreset()
Tries to find mitkRigidRegistrationPresets.xml in /mitk/Config and loads all presets stored in this f...
static Pointer New()
RigidRegistrationObserver::Pointer m_Observer
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetFixedMask(Image::Pointer fixedMask)
static Pointer New()
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
static Pointer New()
static Pointer New()
virtual void SetMovingMask(Image::Pointer movingMask)
InputImageType * GetInput(void)
virtual void SetReferenceImage(Image::Pointer fixedImage)