ANIMA  4.0
animaMCMBlockMatcher.hxx
Go to the documentation of this file.
1 #pragma once
2 #include <animaMCMBlockMatcher.h>
3 
4 /* Similarity measures */
10 
12 #include <animaMCMConstants.h>
13 
14 namespace anima
15 {
16 
17 template <typename TInputImageType>
20 {
21  m_SimilarityType = MCMMeanSquares;
22 
23  m_SmallDelta = anima::DiffusionSmallDelta;
24  m_BigDelta = anima::DiffusionBigDelta;
25 }
26 
27 template <typename TInputImageType>
28 bool
31 {
32  return false;
33 }
34 
35 template <typename TInputImageType>
39 {
40  typename MCMInterpolatorType::Pointer interpolator = MCMInterpolatorType::New();
41  interpolator->SetReferenceOutputModel(this->GetReferenceImage()->GetDescriptionModel());
42 
43  interpolator->Register();
44  return interpolator;
45 }
46 
47 template <typename TInputImageType>
48 void
51 {
52  typedef typename TInputImageType::IOPixelType InputPixelType;
54  typedef typename InitializerType::Pointer InitializerPointer;
55 
56  InitializerPointer initPtr = InitializerType::New();
57  initPtr->AddReferenceImage(this->GetReferenceImage());
58 
59  if (this->GetNumberOfWorkUnits() != 0)
60  initPtr->SetNumberOfThreads(this->GetNumberOfWorkUnits());
61 
62  initPtr->SetPercentageKept(this->GetBlockPercentageKept());
63  initPtr->SetBlockSize(this->GetBlockSize());
64  initPtr->SetBlockSpacing(this->GetBlockSpacing());
65  initPtr->SetOrientedModelVarianceThreshold(this->GetBlockVarianceThreshold());
66 
67  initPtr->SetRequestedRegion(this->GetReferenceImage()->GetLargestPossibleRegion());
68 
69  this->SetBlockRegions(initPtr->GetOutput());
70  this->SetBlockPositions(initPtr->GetOutputPositions());
71 
72  std::cout << "Generated " << this->GetBlockRegions().size() << " blocks..." << std::endl;
73 
74  this->GetBlockTransformPointers().resize(this->GetBlockRegions().size());
75  std::vector <double> newBlockWeights(this->GetBlockRegions().size(),0);
76  this->SetBlockWeights(newBlockWeights);
77  for (unsigned int i = 0;i < this->GetBlockRegions().size();++i)
78  this->GetBlockTransformPointer(i) = this->GetNewBlockTransform(this->GetBlockPositions()[i]);
79 }
80 
81 template <typename TInputImageType>
85 {
86  MetricPointer metric;
87 
88  switch(m_SimilarityType)
89  {
92  {
93  typedef anima::MCMPairingMeanSquaresImageToImageMetric<typename InputImageType::IOPixelType, typename InputImageType::IOPixelType,
94  InputImageType::ImageDimension > MetricType;
95 
96  typename MetricType::Pointer tmpMetric = MetricType::New();
97  tmpMetric->SetOneToOneMapping(m_SimilarityType == MCMOneToOneBasicMeanSquares);
98  metric = tmpMetric;
99  break;
100  }
101 
102  case MTCorrelation:
103  {
104  typedef anima::MTPairingCorrelationImageToImageMetric <typename InputImageType::IOPixelType, typename InputImageType::IOPixelType,
105  InputImageType::ImageDimension > MetricType;
106 
107  typename MetricType::Pointer tmpMetric = MetricType::New();
108  metric = tmpMetric;
109  break;
110  }
111 
112  case MCMCorrelation:
113  {
114  typedef anima::MCMCorrelationImageToImageMetric<typename InputImageType::IOPixelType, typename InputImageType::IOPixelType,
115  InputImageType::ImageDimension > MetricType;
116 
117  typename MetricType::Pointer tmpMetric = MetricType::New();
118  tmpMetric->SetSmallDelta(m_SmallDelta);
119  tmpMetric->SetBigDelta(m_BigDelta);
120  tmpMetric->SetGradientStrengths(m_GradientStrengths);
121  tmpMetric->SetGradientDirections(m_GradientDirections);
122  if ((m_GradientStrengths.size() > 0)&&(m_GradientDirections.size() > 0))
123  tmpMetric->SetForceApproximation(true);
124 
125  metric = tmpMetric;
126  break;
127  }
128 
129  case MCMMeanSquares:
130  default:
131  {
132  typedef anima::MCMMeanSquaresImageToImageMetric<typename InputImageType::IOPixelType, typename InputImageType::IOPixelType,
133  InputImageType::ImageDimension > MetricType;
134 
135  typename MetricType::Pointer tmpMetric = MetricType::New();
136  tmpMetric->SetSmallDelta(m_SmallDelta);
137  tmpMetric->SetBigDelta(m_BigDelta);
138  tmpMetric->SetGradientStrengths(m_GradientStrengths);
139  tmpMetric->SetGradientDirections(m_GradientDirections);
140  if ((m_GradientStrengths.size() > 0)&&(m_GradientDirections.size() > 0))
141  tmpMetric->SetForceApproximation(true);
142 
143  metric = tmpMetric;
144  break;
145  }
146  }
147 
149  BaseMetricType *baseMetric = dynamic_cast <BaseMetricType *> (metric.GetPointer());
150 
151  if (this->GetBlockTransformType() == Superclass::Translation)
152  baseMetric->SetModelRotation(BaseMetricType::NONE);
153  else
154  baseMetric->SetModelRotation((typename BaseMetricType::ModelReorientationType)m_ModelRotationType);
155 
156  typename MCMInterpolatorType::Pointer interpolator = this->CreateInterpolator();
157 
158  baseMetric->SetInterpolator(interpolator);
159 
160  baseMetric->SetFixedImage(this->GetReferenceImage());
161  baseMetric->SetMovingImage(this->GetMovingImage());
162 
163  return metric;
164 }
165 
166 template <typename TInputImageType>
167 double
169 ::ComputeBlockWeight(double val, unsigned int block)
170 {
171  return 1.0;
172 }
173 
174 template <typename TInputImageType>
175 void
177 ::BlockMatchingSetup(MetricPointer &metric, unsigned int block)
178 {
179  // For transform related init
180  this->Superclass::BlockMatchingSetup(metric,block);
181 
182  // Metric specific init
184  InternalMetricType *tmpMetric = dynamic_cast <InternalMetricType *> (metric.GetPointer());
185  tmpMetric->SetFixedImageRegion(this->GetBlockRegion(block));
186  tmpMetric->SetTransform(this->GetBlockTransformPointer(block));
187  tmpMetric->Initialize();
188 
189  typedef anima::MCMPairingMeanSquaresImageToImageMetric <typename InputImageType::IOPixelType,
190  typename InputImageType::IOPixelType,
191  InputImageType::ImageDimension > MCMBasicMeanSquaresMetricType;
192 
193  typedef anima::MTPairingCorrelationImageToImageMetric <typename InputImageType::IOPixelType,
194  typename InputImageType::IOPixelType,
195  InputImageType::ImageDimension > MTPairingCorrelationMetricType;
196 
197  typedef anima::MCMMeanSquaresImageToImageMetric <typename InputImageType::IOPixelType,
198  typename InputImageType::IOPixelType,
199  InputImageType::ImageDimension > MCMMeanSquaresMetricType;
200 
201  typedef anima::MCMCorrelationImageToImageMetric <typename InputImageType::IOPixelType,
202  typename InputImageType::IOPixelType,
203  InputImageType::ImageDimension > MCMCorrelationMetricType;
204 
205  switch(m_SimilarityType)
206  {
207  case MCMMeanSquares:
208  ((MCMMeanSquaresMetricType *)metric.GetPointer())->PreComputeFixedValues();
209  break;
210  case MTCorrelation:
211  ((MTPairingCorrelationMetricType *)metric.GetPointer())->PreComputeFixedValues();
212  break;
213  case MCMCorrelation:
214  ((MCMCorrelationMetricType *)metric.GetPointer())->PreComputeFixedValues();
215  break;
216  case MCMBasicMeanSquares:
218  default:
219  ((MCMBasicMeanSquaresMetricType *)metric.GetPointer())->PreComputeFixedValues();
220  break;
221  }
222 }
223 
224 } // end namespace anima
virtual MetricPointer SetupMetric()
virtual void SetFixedImageRegion(FixedImageRegionType _arg)
Superclass::MetricPointer MetricPointer
itk::SingleValuedCostFunction MetricType
virtual void SetModelRotation(ModelReorientationType _arg)
const double DiffusionBigDelta
Default big delta value (classical values)
const double DiffusionSmallDelta
Default small delta value (classical values)
Superclass::MetricPointer MetricPointer
virtual void BlockMatchingSetup(MetricPointer &metric, unsigned int block)
virtual double ComputeBlockWeight(double val, unsigned int block)
Multi-tensor correlation similarity measure as defined by Taquet et al, based on pairing of the indiv...
virtual MCMInterpolatorType * CreateInterpolator()