ANIMA  4.0
animaTensorBlockMatcher.hxx
Go to the documentation of this file.
1 #pragma once
3 
4 /* Similarity measures */
9 
11 
12 namespace anima
13 {
14 
15 template <typename TInputImageType>
18 {
19  m_SimilarityType = TensorOrientedGeneralizedCorrelation;
20  m_ModelRotationType = FiniteStrain;
21 }
22 
23 template <typename TInputImageType>
24 bool
27 {
28  if (m_SimilarityType == TensorMeanSquares)
29  return false;
30 
31  return true;
32 }
33 
34 template <typename TInputImageType>
38 {
39  MetricPointer metric;
40 
41  switch(m_SimilarityType)
42  {
43  case TensorMeanSquares:
44  {
45  typedef anima::TensorMeanSquaresImageToImageMetric<typename InputImageType::IOPixelType,
46  typename InputImageType::IOPixelType, InputImageType::ImageDimension > MetricType;
47 
48  metric = MetricType::New();
49  break;
50  }
51 
54  {
55  typedef anima::TensorGeneralizedCorrelationImageToImageMetric<typename InputImageType::IOPixelType,
56  typename InputImageType::IOPixelType, InputImageType::ImageDimension > MetricType;
57 
58  typename MetricType::Pointer tmpMetric = MetricType::New();
59 
60  tmpMetric->SetOrientationPenalty(m_SimilarityType == TensorOrientedGeneralizedCorrelation);
61  tmpMetric->SetVarianceThreshold(this->GetBlockVarianceThreshold());
62 
63  metric = tmpMetric;
64  break;
65  }
66 
67  case TensorCorrelation:
68  default:
69  {
70  typedef anima::TensorCorrelationImageToImageMetric<typename InputImageType::IOPixelType,
71  typename InputImageType::IOPixelType, InputImageType::ImageDimension > MetricType;
72 
73  metric = MetricType::New();
74  break;
75  }
76  }
77 
79  BaseMetricType *baseMetric = dynamic_cast <BaseMetricType *> (metric.GetPointer());
80 
81  if (this->GetBlockTransformType() == Superclass::Translation)
82  baseMetric->SetModelRotation(BaseMetricType::NONE);
83  else
84  baseMetric->SetModelRotation((typename BaseMetricType::ModelReorientationType)m_ModelRotationType);
85 
87  typename LocalInterpolatorType::Pointer interpolator = LocalInterpolatorType::New();
88 
89  baseMetric->SetInterpolator(interpolator);
90 
91  baseMetric->SetFixedImage(this->GetReferenceImage());
92  baseMetric->SetMovingImage(this->GetMovingImage());
93  interpolator->SetInputImage(this->GetMovingImage());
94 
95  return metric;
96 }
97 
98 template <typename TInputImageType>
99 double
101 ::ComputeBlockWeight(double val, unsigned int block)
102 {
103  switch (m_SimilarityType)
104  {
105  case TensorMeanSquares:
106  return 1;
107 
108  default:
109  return val;
110  }
111 }
112 
113 template <typename TInputImageType>
114 void
116 ::BlockMatchingSetup(MetricPointer &metric, unsigned int block)
117 {
118  // For transform related init
119  this->Superclass::BlockMatchingSetup(metric,block);
120 
121  // Metric specific init
123  InternalMetricType *tmpMetric = dynamic_cast <InternalMetricType *> (metric.GetPointer());
124  tmpMetric->SetFixedImageRegion(this->GetBlockRegion(block));
125  tmpMetric->SetTransform(this->GetBlockTransformPointer(block));
126  tmpMetric->Initialize();
127 
128  typedef anima::TensorCorrelationImageToImageMetric <typename InputImageType::IOPixelType,
129  typename InputImageType::IOPixelType,
130  InputImageType::ImageDimension > TensorCorrelationMetricType;
131 
132 
133  typedef anima::TensorGeneralizedCorrelationImageToImageMetric <typename InputImageType::IOPixelType,
134  typename InputImageType::IOPixelType,
135  InputImageType::ImageDimension > TensorGeneralizedMetricType;
136 
137 
138  if ((m_SimilarityType == TensorGeneralizedCorrelation)||(m_SimilarityType == TensorOrientedGeneralizedCorrelation))
139  ((TensorGeneralizedMetricType *)metric.GetPointer())->PreComputeFixedValues();
140 
141  if (m_SimilarityType == TensorCorrelation)
142  ((TensorCorrelationMetricType *)metric.GetPointer())->PreComputeFixedValues();
143 }
144 
145 } // end namespace anima
virtual double ComputeBlockWeight(double val, unsigned int block)
virtual MetricPointer SetupMetric()
virtual void SetFixedImageRegion(FixedImageRegionType _arg)
virtual void BlockMatchingSetup(MetricPointer &metric, unsigned int block)
itk::SingleValuedCostFunction MetricType
virtual void SetModelRotation(ModelReorientationType _arg)
Superclass::MetricPointer MetricPointer
Tensor correlation similarity measure as defined by Taquet et al.
Superclass::MetricPointer MetricPointer