ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkFEMImageMetricLoad.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkFEMImageMetricLoad_h
19 #define itkFEMImageMetricLoad_h
20 
21 #include "itkFEMLoadElementBase.h"
22 
23 #include "itkImage.h"
25 
30 #include "itkDerivativeOperator.h"
33 #include "vnl/vnl_math.h"
34 
39 
40 namespace itk
41 {
42 namespace fem
43 {
68 template <typename TMoving, typename TFixed>
70 {
71 public:
72 
78 
80  itkSimpleNewMacro(Self);
81 
83  itkTypeMacro(ImageMetricLoad, LoadElement);
84 
87  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE;
88 
89  // Necessary typedefs for dealing with images BEGIN
90  typedef typename LoadElement::Float Float;
91 
92  typedef TMoving MovingType;
93  typedef typename MovingType::ConstPointer MovingConstPointer;
94  typedef MovingType * MovingPointer;
95  typedef TFixed FixedType;
96  typedef FixedType * FixedPointer;
97  typedef typename FixedType::ConstPointer FixedConstPointer;
98 
100  itkStaticConstMacro(ImageDimension, unsigned int,
101  MovingType::ImageDimension);
102 
105 
106  typedef NeighborhoodIterator<MovingType>
108  typedef typename MovingNeighborhoodIteratorType::IndexType
110  typedef typename MovingNeighborhoodIteratorType::RadiusType
112  typedef NeighborhoodIterator<FixedType>
114  typedef typename FixedNeighborhoodIteratorType::IndexType
116  typedef typename FixedNeighborhoodIteratorType::RadiusType
118 
119 // IMAGE DATA
120  typedef typename MovingType::PixelType RefPixelType;
121  typedef typename FixedType::PixelType TarPixelType;
122  typedef Float PixelType;
123  typedef Float ComputationType;
124  typedef Image<RefPixelType, itkGetStaticConstMacro(ImageDimension)> RefImageType;
125  typedef Image<TarPixelType, itkGetStaticConstMacro(ImageDimension)> TarImageType;
126  typedef Image<PixelType, itkGetStaticConstMacro(ImageDimension)> ImageType;
127  typedef vnl_vector<Float> VectorType;
128 
129 // Necessary typedefs for dealing with images END
130 
131 // ------------------------------------------------------------
132 // Set up the metrics
133 // ------------------------------------------------------------
134  typedef double
136  typedef Transform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension),
137  itkGetStaticConstMacro(ImageDimension)> TransformBaseType;
138  typedef TranslationTransform<CoordinateRepresentationType,
139  itkGetStaticConstMacro(ImageDimension)> DefaultTransformType;
140 
142  typedef ImageToImageMetric<FixedType, MovingType> MetricBaseType;
143  typedef typename MetricBaseType::Pointer MetricBaseTypePointer;
144 
146 
147  typedef MeanSquaresImageToImageMetric<MovingType, FixedType> MeanSquaresMetricType;
148 
150 
151  typedef MeanSquaresMetricType DefaultMetricType;
152  typedef typename DefaultTransformType::ParametersType ParametersType;
153  typedef typename DefaultTransformType::JacobianType JacobianType;
154 
155  typedef unsigned long ElementIdentifier;
156  typedef VectorContainer<ElementIdentifier, Element::Pointer> ElementContainerType;
157 // ------------------------------------------------------------
158 // Set up an Interpolator
159 // ------------------------------------------------------------
161 
163  typedef float RealType;
164  typedef CovariantVector<RealType,
165  itkGetStaticConstMacro(ImageDimension)> GradientPixelType;
166  typedef Image<GradientPixelType,
167  itkGetStaticConstMacro(ImageDimension)> GradientImageType;
168  typedef SmartPointer<GradientImageType> GradientImagePointer;
169  typedef GradientRecursiveGaussianImageFilter<ImageType,
170  GradientImageType>
172  // typedef typename GradientImageFilterType::Pointer
173  // GradientImageFilterPointer;
175 
176 // FUNCTIONS
177 
179  void SetMetric(MetricBaseTypePointer MP)
180  {
181  m_Metric = MP;
182  }
183 
186  {
187  m_RefImage = R;
188  m_RefSize = m_RefImage->GetLargestPossibleRegion().GetSize();
189  }
191 
193  {
194  m_Metric->SetMovingImage(R);
195  m_RefSize = R->GetLargestPossibleRegion().GetSize();
196  }
197 
200  {
201  m_TarImage = T;
202  m_TarSize = T->GetLargestPossibleRegion().GetSize();
203  }
205 
207  {
208  m_Metric->SetFixedImage(T);
209  m_TarSize = T->GetLargestPossibleRegion().GetSize();
210  }
211 
213  {
214  return m_RefImage;
215  }
217  {
218  return m_TarImage;
219  }
220 
223  {
224  m_MetricRadius = T;
225  }
226 
229  {
230  return m_MetricRadius;
231  }
232 
237  void SetNumberOfIntegrationPoints(unsigned int i)
238  {
240  }
242  {
244  }
246 
250  void SetSign(Float s)
251  {
252  m_Sign = s;
253  }
254 
256  void SetTemp(Float s)
257  {
258  m_Temp = s;
259  }
260 
262  void SetGamma(Float s)
263  {
264  m_Gamma = s;
265  }
266 
270  virtual void SetSolution(Solution::ConstPointer ptr) ITK_OVERRIDE
271  {
272  m_Solution = ptr;
273  }
274 
278  virtual Solution::ConstPointer GetSolution() ITK_OVERRIDE
279  {
280  return m_Solution;
281  }
282 
286  Float GetMetric(VectorType InVec);
287 
288  VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition);
289 
290  VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition);
291 
292  // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT
293  Float GetSolution(unsigned int i, unsigned int which = 0)
294  {
295  return m_Solution->GetSolutionValue(i, which);
296  }
297 
298 // define the copy constructor
299 // ImageMetricLoad(const ImageMetricLoad& LMS);
300 
301  void InitializeMetric();
302 
303  ImageMetricLoad(); // cannot be private until we always use smart pointers
305 
307 
312 
314  {
315  return new ImageMetricLoad;
316  }
317 
319  // void InitializeGradientImage();
321  {
323  }
325  {
326  return m_MetricGradientImage;
327  }
329 
331  {
332  std::cout << " energy " << m_Energy << std::endl;
333  }
335  {
336  return m_Energy;
337  }
338  void SetCurrentEnergy(double e)
339  {
340  m_Energy = e;
341  }
342 
343  // FIXME - Documentation
344  virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType & Fe) ITK_OVERRIDE;
345 
346 protected:
347  virtual void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
348 
349 private:
355  typename MovingType::SizeType m_RefSize;
356  typename FixedType::SizeType m_TarSize;
358  unsigned int m_SolutionIndex;
359  unsigned int m_SolutionIndex2;
363 
368 
369  mutable double m_Energy;
370 
371 private:
372 
373 };
374 }
375 } // end namespace fem/itk
376 
377 #ifndef ITK_MANUAL_INSTANTIATION
378 #include "itkFEMImageMetricLoad.hxx"
379 #endif
380 
381 #endif
MovingType::ConstPointer MovingConstPointer
Light weight base class for most itk classes.
VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition)
void SetMetricGradientImage(GradientImageType *g)
MetricBaseTypePointer m_Metric
GradientImageType * m_MetricGradientImage
void SetMovingImage(MovingType *R)
SmartPointer< const Self > ConstPointer
void SetNumberOfIntegrationPoints(unsigned int i)
void SetMetricFixedImage(FixedType *T)
unsigned int GetNumberOfIntegrationPoints()
void SetMetricMovingImage(MovingType *R)
MovingType::PixelType RefPixelType
MovingNeighborhoodIteratorType::IndexType MovingNeighborhoodIndexType
SmartPointer< Self > Pointer
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition)
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
virtual ::itk::LightObject::Pointer CreateAnother(void) const override
virtual void PrintSelf(std::ostream &os, Indent indent) const override
General image pair load that uses the itkImageToImageMetrics.
void SetMetric(MetricBaseTypePointer MP)
virtual Solution::ConstPointer GetSolution() override
Provides functions to access the values of the solution vector.
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
virtual void SetSolution(Solution::ConstPointer ptr) override
Computes similarity between two images to be registered.
Float GetSolution(unsigned int i, unsigned int which=0)
Computes the mutual information between two images to be registered.
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
MovingNeighborhoodIteratorType::RadiusType MovingRadiusType
vnl_vector< Float > VectorType
TransformBaseType::Pointer m_Transform
static const unsigned int ImageDimension
Float GetMetric(VectorType InVec)
Virtual element load base class.
FixedNeighborhoodIteratorType::RadiusType FixedRadiusType
DefaultTransformType::ParametersType ParametersType
DefaultTransformType::JacobianType JacobianType
Linearly interpolate an image at specified positions.
VectorType Fe(VectorType, VectorType)
Float EvaluateMetricGivenSolution(Element::ArrayType *el, Float step=1.0)
static Baseclass * NewImageMetricLoad(void)
Array for FEMP objects.
Definition: itkFEMPArray.h:40
FixedType::ConstPointer FixedConstPointer
Abstract base element class.
GradientImageType * GetMetricGradientImage()
Float EvaluateMetricGivenSolution1(Element::ArrayType *el, Float step=1.0)
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Translation transformation of a vector space (e.g. space coordinates)
MovingRadiusType GetMetricRadius()
FixedType::PixelType TarPixelType
Computes similarity between regions of two images.
MovingType::SizeType m_RefSize
A templated class holding a n-Dimensional covariant vector.
virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex=0) const =0
FixedNeighborhoodIteratorType::IndexType FixedNeighborhoodIndexType
Solution::ConstPointer m_Solution
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Templated n-dimensional image class.
Definition: itkImage.h:75
virtual void ApplyLoad(Element::ConstPointer element, Element::VectorType &Fe) override
void SetMetricRadius(MovingRadiusType T)
InterpolatorType::Pointer m_Interpolator