As I understand the metric is calculated using the fixedImage, movingImage and the current transform parameters based on the following approach:<br><br>1) Apply transform parameters to the movingImage (transform moving image into the fixed image space, itkSoftwareGuide Figure 8.43 page 410 [*] ).<br>
<br>2) Run through the fixed and moving image indicies and sum the intensity difference.<br><br>But when I look into the code of:<br><br>itkMeanSquaresImageToImageMetric.txx<br><br>it seems that its not how its done.<br><br>
The function:<br><br>GetValueAndDerivative(const TransformParametersType &amp; parameters, <br>                        MeasureType &amp; value, DerivativeType  &amp; derivative) const<br><br>computes the metric value and the gradient. Its basically done by running through the fixed image and summing the difference between the fixed image values and the transformed fixed image values:<br>
<br><br>      const RealType diff = movingValue - fixedValue;   <br>      measure += diff * diff;<br><br><br><br>where:<br><br> OutputPointType transformedPoint = this-&gt;m_Transform-&gt;TransformPoint( inputPoint );  // Using the current fixed image inputPoint<br>
 const RealType movingValue  = this-&gt;m_Interpolator-&gt;Evaluate( transformedPoint );<br> const RealType fixedValue     = ti.Value(); // The current value of the pixel in the fixed image.<br><br>As I understand the current transform parameters are applied to the fixed image and the corresponding transformed pixel value is computed. So the &#39;measure&#39; is actually the difference between the fixed and the transformed fixed image:<br>
<br>1) measure = fixed - T(fixed)<br><br><br>But should the metric not be computed between the fixed and the transformed Moving image as described in the itkSoftwawreGuide:<br><br>2) measure = fixed - T(moving)<br><br>?<br>
<br><br><br><br><br><br>* Caption Figure 8.43:<br><br>&quot;The moving image is mapped into the fixed image space under some spatial transformation.<br>An iterator walks through the fixed image and its coordinates are mapped onto the moving image.&quot;<br>
<br>Later on the same page:<br><br>&quot;Figure 8.43 (left) illustrates the mapping of the fixed image space onto the moving image space.<br>The transform maps points from the fixed image coordinate system onto the moving image coordinate system&quot;<br>
<br><br>I assume that the second quote is similar to the implementation, but I still don&#39;t see how that is correct.<br><br><br><br><br><br><br><br><br><br><br><br><br>  while(!ti.IsAtEnd())<br>    {<br><br>    index = ti.GetIndex();<br>
    <br>    InputPointType inputPoint;<br>    fixedImage-&gt;TransformIndexToPhysicalPoint( index, inputPoint );<br><br>    if( this-&gt;m_FixedImageMask &amp;&amp; !this-&gt;m_FixedImageMask-&gt;IsInside( inputPoint ) )<br>
      {<br>      ++ti;<br>      continue;<br>      }<br><br>    OutputPointType transformedPoint = this-&gt;m_Transform-&gt;TransformPoint( inputPoint );<br><br>    if( this-&gt;m_MovingImageMask &amp;&amp; !this-&gt;m_MovingImageMask-&gt;IsInside( transformedPoint ) )<br>
      {<br>      ++ti;<br>      continue;<br>      }<br><br>    if( this-&gt;m_Interpolator-&gt;IsInsideBuffer( transformedPoint ) )<br>      {<br>      const RealType movingValue  = this-&gt;m_Interpolator-&gt;Evaluate( transformedPoint );<br>
<br>      const TransformJacobianType &amp; jacobian =<br>        this-&gt;m_Transform-&gt;GetJacobian( inputPoint ); <br><br>      <br>      const RealType fixedValue     = ti.Value();<br>      this-&gt;m_NumberOfPixelsCounted++;<br>
<br>      const RealType diff = movingValue - fixedValue; <br>