Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMetricFactory.txx
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 
17 #include "mitkMetricFactory.h"
18 #include "mitkMetricParameters.h"
19 
20 #include <itkCorrelationCoefficientHistogramImageToImageMetric.h>
21 #include <itkGradientDifferenceImageToImageMetric.h>
22 #include <itkKappaStatisticImageToImageMetric.h>
23 #include <itkKullbackLeiblerCompareHistogramImageToImageMetric.h>
24 #include <itkMatchCardinalityImageToImageMetric.h>
25 #include <itkMattesMutualInformationImageToImageMetric.h>
26 #include <itkMeanReciprocalSquareDifferenceImageToImageMetric.h>
27 #include <itkMeanSquaresHistogramImageToImageMetric.h>
28 #include <itkMeanSquaresImageToImageMetric.h>
29 #include <itkMutualInformationHistogramImageToImageMetric.h>
30 #include <itkMutualInformationImageToImageMetric.h>
31 #include <itkNormalizedCorrelationImageToImageMetric.h>
32 #include <itkNormalizedMutualInformationHistogramImageToImageMetric.h>
33 
34 namespace mitk
35 {
36  template <class TPixelType, unsigned int VImageDimension>
37  MetricFactory<TPixelType, VImageDimension>::MetricFactory() : m_MetricParameters(nullptr)
38  {
39  }
40 
41  template <class TPixelType, unsigned int VImageDimension>
42  typename MetricFactory<TPixelType, VImageDimension>::MetricPointer
43  MetricFactory<TPixelType, VImageDimension>::GetMetric()
44  {
45  int metric = m_MetricParameters->GetMetric();
46  if (metric == MetricParameters::MEANSQUARESIMAGETOIMAGEMETRIC)
47  {
48  typename itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
49  itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType>::New();
50  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
51  return MetricPointer.GetPointer();
52  }
53  else if (metric == MetricParameters::NORMALIZEDCORRELATIONIMAGETOIMAGEMETRIC)
54  {
55  typename itk::NormalizedCorrelationImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
56  itk::NormalizedCorrelationImageToImageMetric<FixedImageType, MovingImageType>::New();
57  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
58  return MetricPointer.GetPointer();
59  }
60  else if (metric == MetricParameters::GRADIENTDIFFERENCEIMAGETOIMAGEMETRIC)
61  {
62  typename itk::GradientDifferenceImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
63  itk::GradientDifferenceImageToImageMetric<FixedImageType, MovingImageType>::New();
64  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
65  return MetricPointer.GetPointer();
66  }
67  else if (metric == MetricParameters::KULLBACKLEIBLERCOMPAREHISTOGRAMIMAGETOIMAGEMETRIC)
68  {
69  typename itk::KullbackLeiblerCompareHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer
70  MetricPointer = itk::KullbackLeiblerCompareHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
71  unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsKullbackLeiblerCompareHistogram();
72  typename itk::KullbackLeiblerCompareHistogramImageToImageMetric<FixedImageType,
73  MovingImageType>::HistogramType::SizeType
74  histogramSize;
75  histogramSize[0] = nBins;
76  histogramSize[1] = nBins;
77  MetricPointer->SetHistogramSize(histogramSize);
78  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
79  return MetricPointer.GetPointer();
80  }
81  else if (metric == MetricParameters::CORRELATIONCOEFFICIENTHISTOGRAMIMAGETOIMAGEMETRIC)
82  {
83  typename itk::CorrelationCoefficientHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer
84  MetricPointer = itk::CorrelationCoefficientHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
85  unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsCorrelationCoefficientHistogram();
86  typename itk::CorrelationCoefficientHistogramImageToImageMetric<FixedImageType,
87  MovingImageType>::HistogramType::SizeType
88  histogramSize;
89  histogramSize[0] = nBins;
90  histogramSize[1] = nBins;
91  MetricPointer->SetHistogramSize(histogramSize);
92  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
93  return MetricPointer.GetPointer();
94  }
95  else if (metric == MetricParameters::MEANSQUARESHISTOGRAMIMAGETOIMAGEMETRIC)
96  {
97  typename itk::MeanSquaresHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
98  itk::MeanSquaresHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
99  unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsMeanSquaresHistogram();
100  typename itk::MeanSquaresHistogramImageToImageMetric<FixedImageType, MovingImageType>::HistogramType::SizeType
101  histogramSize;
102  histogramSize[0] = nBins;
103  histogramSize[1] = nBins;
104  MetricPointer->SetHistogramSize(histogramSize);
105  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
106  return MetricPointer.GetPointer();
107  }
108  else if (metric == MetricParameters::MUTUALINFORMATIONHISTOGRAMIMAGETOIMAGEMETRIC)
109  {
110  typename itk::MutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer
111  MetricPointer = itk::MutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
112  unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsMutualInformationHistogram();
113  typename itk::MutualInformationHistogramImageToImageMetric<FixedImageType,
114  MovingImageType>::HistogramType::SizeType
115  histogramSize;
116  histogramSize[0] = nBins;
117  histogramSize[1] = nBins;
118  MetricPointer->SetHistogramSize(histogramSize);
119  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
120  return MetricPointer.GetPointer();
121  }
122  else if (metric == MetricParameters::NORMALIZEDMUTUALINFORMATIONHISTOGRAMIMAGETOIMAGEMETRIC)
123  {
124  typename itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer
125  MetricPointer =
126  itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
127  unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsNormalizedMutualInformationHistogram();
128  typename itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType,
129  MovingImageType>::HistogramType::SizeType
130  histogramSize;
131  histogramSize[0] = nBins;
132  histogramSize[1] = nBins;
133  MetricPointer->SetHistogramSize(histogramSize);
134  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
135  return MetricPointer.GetPointer();
136  }
137  else if (metric == MetricParameters::MATTESMUTUALINFORMATIONIMAGETOIMAGEMETRIC)
138  {
139  typename itk::MattesMutualInformationImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
140  itk::MattesMutualInformationImageToImageMetric<FixedImageType, MovingImageType>::New();
141  bool useSampling = m_MetricParameters->GetUseSamplesMattesMutualInformation();
142  if (useSampling)
143  {
144  // set the number of samples to use
145  MetricPointer->SetNumberOfSpatialSamples(m_MetricParameters->GetSpatialSamplesMattesMutualInformation());
146  }
147  else
148  {
149  MetricPointer->UseAllPixelsOn();
150  }
151  MetricPointer->SetNumberOfHistogramBins(m_MetricParameters->GetNumberOfHistogramBinsMattesMutualInformation());
152  MetricPointer->ReinitializeSeed(76926294);
153  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
154  return MetricPointer.GetPointer();
155  }
156  else if (metric == MetricParameters::MEANRECIPROCALSQUAREDIFFERENCEIMAGETOIMAGEMETRIC)
157  {
158  typename itk::MeanReciprocalSquareDifferenceImageToImageMetric<FixedImageType, MovingImageType>::Pointer
159  MetricPointer = itk::MeanReciprocalSquareDifferenceImageToImageMetric<FixedImageType, MovingImageType>::New();
160  //------------------------------------------------------------
161  // The lambda value is the intensity difference that should
162  // make the metric drop by 50%
163  //------------------------------------------------------------
164  MetricPointer->SetLambda(m_MetricParameters->GetLambdaMeanReciprocalSquareDifference());
165  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
166  return MetricPointer.GetPointer();
167  }
168  else if (metric == MetricParameters::MUTUALINFORMATIONIMAGETOIMAGEMETRIC)
169  {
170  typename itk::MutualInformationImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
171  itk::MutualInformationImageToImageMetric<FixedImageType, MovingImageType>::New();
172  MetricPointer->SetNumberOfSpatialSamples(m_MetricParameters->GetSpatialSamplesMutualInformation());
173  MetricPointer->SetFixedImageStandardDeviation(
174  m_MetricParameters->GetFixedImageStandardDeviationMutualInformation());
175  MetricPointer->SetMovingImageStandardDeviation(
176  m_MetricParameters->GetMovingImageStandardDeviationMutualInformation());
177  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
178  return MetricPointer.GetPointer();
179  }
180  else if (metric == MetricParameters::MATCHCARDINALITYIMAGETOIMAGEMETRIC)
181  {
182  typename itk::MatchCardinalityImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
183  itk::MatchCardinalityImageToImageMetric<FixedImageType, MovingImageType>::New();
184  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
185  return MetricPointer.GetPointer();
186  }
187  else if (metric == MetricParameters::KAPPASTATISTICIMAGETOIMAGEMETRIC)
188  {
189  typename itk::KappaStatisticImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
190  itk::KappaStatisticImageToImageMetric<FixedImageType, MovingImageType>::New();
191  MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
192  return MetricPointer.GetPointer();
193  }
194  return NULL;
195  }
196 } // end namespace