1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 #include "mitkMetricFactory.h"
18 #include "mitkMetricParameters.h"
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>
36 template <class TPixelType, unsigned int VImageDimension>
37 MetricFactory<TPixelType, VImageDimension>::MetricFactory() : m_MetricParameters(nullptr)
41 template <class TPixelType, unsigned int VImageDimension>
42 typename MetricFactory<TPixelType, VImageDimension>::MetricPointer
43 MetricFactory<TPixelType, VImageDimension>::GetMetric()
45 int metric = m_MetricParameters->GetMetric();
46 if (metric == MetricParameters::MEANSQUARESIMAGETOIMAGEMETRIC)
48 typename itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
49 itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType>::New();
50 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
51 return MetricPointer.GetPointer();
53 else if (metric == MetricParameters::NORMALIZEDCORRELATIONIMAGETOIMAGEMETRIC)
55 typename itk::NormalizedCorrelationImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
56 itk::NormalizedCorrelationImageToImageMetric<FixedImageType, MovingImageType>::New();
57 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
58 return MetricPointer.GetPointer();
60 else if (metric == MetricParameters::GRADIENTDIFFERENCEIMAGETOIMAGEMETRIC)
62 typename itk::GradientDifferenceImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
63 itk::GradientDifferenceImageToImageMetric<FixedImageType, MovingImageType>::New();
64 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
65 return MetricPointer.GetPointer();
67 else if (metric == MetricParameters::KULLBACKLEIBLERCOMPAREHISTOGRAMIMAGETOIMAGEMETRIC)
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
75 histogramSize[0] = nBins;
76 histogramSize[1] = nBins;
77 MetricPointer->SetHistogramSize(histogramSize);
78 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
79 return MetricPointer.GetPointer();
81 else if (metric == MetricParameters::CORRELATIONCOEFFICIENTHISTOGRAMIMAGETOIMAGEMETRIC)
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
89 histogramSize[0] = nBins;
90 histogramSize[1] = nBins;
91 MetricPointer->SetHistogramSize(histogramSize);
92 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
93 return MetricPointer.GetPointer();
95 else if (metric == MetricParameters::MEANSQUARESHISTOGRAMIMAGETOIMAGEMETRIC)
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
102 histogramSize[0] = nBins;
103 histogramSize[1] = nBins;
104 MetricPointer->SetHistogramSize(histogramSize);
105 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
106 return MetricPointer.GetPointer();
108 else if (metric == MetricParameters::MUTUALINFORMATIONHISTOGRAMIMAGETOIMAGEMETRIC)
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
116 histogramSize[0] = nBins;
117 histogramSize[1] = nBins;
118 MetricPointer->SetHistogramSize(histogramSize);
119 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
120 return MetricPointer.GetPointer();
122 else if (metric == MetricParameters::NORMALIZEDMUTUALINFORMATIONHISTOGRAMIMAGETOIMAGEMETRIC)
124 typename itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::Pointer
126 itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType, MovingImageType>::New();
127 unsigned int nBins = m_MetricParameters->GetNumberOfHistogramBinsNormalizedMutualInformationHistogram();
128 typename itk::NormalizedMutualInformationHistogramImageToImageMetric<FixedImageType,
129 MovingImageType>::HistogramType::SizeType
131 histogramSize[0] = nBins;
132 histogramSize[1] = nBins;
133 MetricPointer->SetHistogramSize(histogramSize);
134 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
135 return MetricPointer.GetPointer();
137 else if (metric == MetricParameters::MATTESMUTUALINFORMATIONIMAGETOIMAGEMETRIC)
139 typename itk::MattesMutualInformationImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
140 itk::MattesMutualInformationImageToImageMetric<FixedImageType, MovingImageType>::New();
141 bool useSampling = m_MetricParameters->GetUseSamplesMattesMutualInformation();
144 // set the number of samples to use
145 MetricPointer->SetNumberOfSpatialSamples(m_MetricParameters->GetSpatialSamplesMattesMutualInformation());
149 MetricPointer->UseAllPixelsOn();
151 MetricPointer->SetNumberOfHistogramBins(m_MetricParameters->GetNumberOfHistogramBinsMattesMutualInformation());
152 MetricPointer->ReinitializeSeed(76926294);
153 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
154 return MetricPointer.GetPointer();
156 else if (metric == MetricParameters::MEANRECIPROCALSQUAREDIFFERENCEIMAGETOIMAGEMETRIC)
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();
168 else if (metric == MetricParameters::MUTUALINFORMATIONIMAGETOIMAGEMETRIC)
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();
180 else if (metric == MetricParameters::MATCHCARDINALITYIMAGETOIMAGEMETRIC)
182 typename itk::MatchCardinalityImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
183 itk::MatchCardinalityImageToImageMetric<FixedImageType, MovingImageType>::New();
184 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
185 return MetricPointer.GetPointer();
187 else if (metric == MetricParameters::KAPPASTATISTICIMAGETOIMAGEMETRIC)
189 typename itk::KappaStatisticImageToImageMetric<FixedImageType, MovingImageType>::Pointer MetricPointer =
190 itk::KappaStatisticImageToImageMetric<FixedImageType, MovingImageType>::New();
191 MetricPointer->SetComputeGradient(m_MetricParameters->GetComputeGradient());
192 return MetricPointer.GetPointer();