Orfeo Toolbox  3.16
itkMeanReciprocalSquareDifferenceImageToImageMetric.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMeanReciprocalSquareDifferenceImageToImageMetric.txx,v $
5  Language: C++
6  Date: $Date: 2009-01-24 20:02:59 $
7  Version: $Revision: 1.7 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMeanReciprocalSquareDifferenceImageToImageMetric_txx
18 #define __itkMeanReciprocalSquareDifferenceImageToImageMetric_txx
19 
22 
23 namespace itk
24 {
25 
29 template <class TFixedImage, class TMovingImage>
32 {
33  m_Lambda = 1.0;
34  m_Delta = 0.00011;
35 }
36 
37 
41 template <class TFixedImage, class TMovingImage>
42 void
44 ::PrintSelf(std::ostream& os, Indent indent) const
45 {
46  Superclass::PrintSelf( os, indent );
47  os << "Lambda factor = " << m_Lambda << std::endl;
48  os << "Delta value = " << m_Delta << std::endl;
49 }
50 
51 /*
52  * Get the match Measure
53  */
54 template <class TFixedImage, class TMovingImage>
57 ::GetValue( const TransformParametersType & parameters ) const
58 {
59 
60  FixedImageConstPointer fixedImage = this->m_FixedImage;
61 
62  if( !fixedImage )
63  {
64  itkExceptionMacro( << "Fixed image has not been assigned" );
65  }
66 
67  const unsigned int dimension = FixedImageType::ImageDimension;
69 
70  double MovingValue;
71  double FixedValue;
72 
74 
75 
76  FixedIteratorType ti( fixedImage, this->GetFixedImageRegion() );
77 
78  typename FixedImageType::IndexType index;
79 
81 
82  this->m_NumberOfPixelsCounted = 0;
83 
84  this->SetTransformParameters( parameters );
85 
86  while(!ti.IsAtEnd())
87  {
88 
89  index = ti.GetIndex();
90 
91  InputPointType inputPoint;
92  fixedImage->TransformIndexToPhysicalPoint( index, inputPoint );
93 
94  if( this->m_FixedImageMask && !this->m_FixedImageMask->IsInside( inputPoint ) )
95  {
96  ++ti;
97  continue;
98  }
99 
100  TransformType const *transform = this->m_Transform;
101  OutputPointType transformedPoint = transform->TransformPoint( inputPoint );
102 
103  if( this->m_MovingImageMask && !this->m_MovingImageMask->IsInside( transformedPoint ) )
104  {
105  ++ti;
106  continue;
107  }
108 
109  if( this->m_Interpolator->IsInsideBuffer( transformedPoint ) )
110  {
111  MovingValue = this->m_Interpolator->Evaluate( transformedPoint );
112  FixedValue = ti.Get();
113  this->m_NumberOfPixelsCounted++;
114  const double diff = MovingValue - FixedValue;
115  measure += 1.0f / ( 1.0f + m_Lambda* ( diff * diff ) );
116  }
117 
118  ++ti;
119  }
120 
121  return measure;
122 
123 }
124 
128 template < class TFixedImage, class TMovingImage>
129 void
132  DerivativeType & derivative ) const
133 {
134 
135  TransformParametersType testPoint;
136  testPoint = parameters;
137 
138  const unsigned int numberOfParameters = this->GetNumberOfParameters();
139  derivative = DerivativeType( numberOfParameters );
140 
141  for( unsigned int i=0; i<numberOfParameters; i++)
142  {
143  testPoint[i] -= m_Delta;
144  const MeasureType valuep0 = this->GetValue( testPoint );
145  testPoint[i] += 2 * m_Delta;
146  const MeasureType valuep1 = this->GetValue( testPoint );
147  derivative[i] = (valuep1 - valuep0 ) / ( 2 * m_Delta );
148  testPoint[i] = parameters[i];
149  }
150 
151 
152 
153 }
154 
158 template <class TFixedImage, class TMovingImage>
159 void
162  MeasureType & Value, DerivativeType & Derivative) const
163 {
164  Value = this->GetValue( parameters );
165  this->GetDerivative( parameters, Derivative );
166 }
167 
168 } // end namespace itk
169 
170 
171 #endif

Generated at Sat May 18 2013 23:53:03 for Orfeo Toolbox with doxygen 1.8.3.1