17 #ifndef __itkMeanReciprocalSquareDifferenceImageToImageMetric_txx
18 #define __itkMeanReciprocalSquareDifferenceImageToImageMetric_txx
29 template <
class TFixedImage,
class TMovingImage>
41 template <
class TFixedImage,
class TMovingImage>
46 Superclass::PrintSelf( os, indent );
47 os <<
"Lambda factor = " << m_Lambda << std::endl;
48 os <<
"Delta value = " << m_Delta << std::endl;
54 template <
class TFixedImage,
class TMovingImage>
64 itkExceptionMacro( <<
"Fixed image has not been assigned" );
67 const unsigned int dimension = FixedImageType::ImageDimension;
76 FixedIteratorType ti( fixedImage, this->GetFixedImageRegion() );
78 typename FixedImageType::IndexType index;
82 this->m_NumberOfPixelsCounted = 0;
84 this->SetTransformParameters( parameters );
89 index = ti.GetIndex();
92 fixedImage->TransformIndexToPhysicalPoint( index, inputPoint );
94 if( this->m_FixedImageMask && !this->m_FixedImageMask->IsInside( inputPoint ) )
103 if( this->m_MovingImageMask && !this->m_MovingImageMask->IsInside( transformedPoint ) )
109 if( this->m_Interpolator->IsInsideBuffer( transformedPoint ) )
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 ) );
128 template <
class TFixedImage,
class TMovingImage>
136 testPoint = parameters;
138 const unsigned int numberOfParameters = this->GetNumberOfParameters();
141 for(
unsigned int i=0; i<numberOfParameters; i++)
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];
158 template <
class TFixedImage,
class TMovingImage>
164 Value = this->GetValue( parameters );
165 this->GetDerivative( parameters, Derivative );