<div>HI again,</div>
<div>For some reason, my message was discarded when I sent it to the mailing list the first time. I am sending it again. The two images can be found:</div>
<div><a href="http://www.stanford.edu/~mingchao/image/fixedImage.vtk">http://www.stanford.edu/~mingchao/image/fixedImage.vtk</a></div>
<div>and </div>
<div><a href="http://www.stanford.edu/~mingchao/image/movingImage16.vtk">http://www.stanford.edu/~mingchao/image/movingImage16.vtk</a></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Hi,</div>
<div>&nbsp;</div>
<div>I followed a standard procedure to calculate the metric between two images. However, I encountered a problem. Bascally I have two images which are subregions of a big image. When I calculate the metric between these two smaller images, the metric value is always -1 (I am using Normalized Correlation Metric). The code is attached to the end of this message. And the two images are attached as well. I don't understand what is wrong. 
</div>
<div>Thanks,</div>
<div>Ming</div>
<div>&nbsp;</div>
<div>
<p>#include &quot;itkImage.h&quot;<br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkMeanSquaresImageToImageMetric.h&quot;<br>#include &quot;itkNormalizedCorrelationImageToImageMetric.h
 &quot;<br>#include &quot;itkTranslationTransform.h&quot;<br>#include &quot;itkNearestNeighborInterpolateImageFunction.h&quot;<br>#include &quot;itkLinearInterpolateImageFunction.h&quot;</p>
<p><br>int main( int argc, char * argv[] )<br>{<br>&nbsp; if( argc &lt; 3 )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; argv[0] &lt;&lt; &quot;&nbsp; fixedImage&nbsp; movingImage&quot; &lt;&lt; std::endl; 
<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp; const&nbsp;&nbsp;&nbsp;&nbsp; unsigned int&nbsp;&nbsp; Dimension = 2;<br>&nbsp; //typedef&nbsp; unsigned char&nbsp; PixelType;<br>&nbsp; typedef&nbsp; float&nbsp; PixelType;</p>
<p>&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp;&nbsp; ImageType;<br>&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp;&nbsp; ImageType;</p>
<p><br>&nbsp; typedef itk::ImageFileReader&lt; ImageType &gt;&nbsp; ReaderType;</p>
<p>&nbsp; ReaderType::Pointer fixedReader&nbsp; = ReaderType::New();<br>&nbsp; ReaderType::Pointer movingReader = ReaderType::New();</p>
<p>&nbsp; fixedReader-&gt;SetFileName(&nbsp; argv[ 1 ] );<br>&nbsp; movingReader-&gt;SetFileName( argv[ 2 ] );</p>
<p>&nbsp; try <br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; fixedReader-&gt;Update();<br>&nbsp;&nbsp;&nbsp; movingReader-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; catch( itk::ExceptionObject &amp; excep )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception catched !&quot; &lt;&lt; std::endl;
<span></span> <br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp; typedef itk::NormalizedCorrelationImageToImageMetric&lt; ImageType, ImageType &gt;&nbsp; MetricType;</p>
<p>&nbsp; MetricType::Pointer metric = MetricType::New();</p>
<p>&nbsp;</p>
<p>&nbsp; typedef itk::TranslationTransform&lt; double, Dimension &gt;&nbsp; TransformType;</p>
<p>&nbsp; TransformType::Pointer transform = TransformType::New();</p>
<p>&nbsp;</p>
<p>&nbsp; typedef itk::NearestNeighborInterpolateImageFunction&lt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType, double &gt;&nbsp; InterpolatorType;</p>
<p>&nbsp; InterpolatorType::Pointer interpolator = InterpolatorType::New();</p>
<p>&nbsp; typedef TransformType::ParametersType ParametersType;<br>&nbsp; ParametersType displacement( transform-&gt;GetNumberOfParameters() );<br>&nbsp; displacement.Fill(&nbsp; 0.0&nbsp; );</p>
<p>&nbsp; metric-&gt;SetInterpolator( interpolator );<br>&nbsp; metric-&gt;SetTransform( transform );</p>
<p>&nbsp; //transform-&gt;SetIdentity();</p>
<p>&nbsp; ImageType::ConstPointer fixedImage&nbsp; = fixedReader-&gt;GetOutput();<br>&nbsp; ImageType::ConstPointer movingImage = movingReader-&gt;GetOutput();</p>
<p>&nbsp; metric-&gt;SetFixedImage(&nbsp; fixedImage&nbsp; );<br>&nbsp; metric-&gt;SetMovingImage( movingImage );</p>
<p>&nbsp; metric-&gt;SetFixedImageRegion(&nbsp; fixedImage-&gt;GetBufferedRegion()&nbsp; );</p>
<p>&nbsp; try <br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; metric-&gt;Initialize();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; catch( itk::ExceptionObject &amp; excep )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception catched !&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; excep &lt;&lt; std::endl; 
<br>&nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp; const double value = metric-&gt;GetValue( displacement );</p>
<p>&nbsp; std::cout &lt;&lt; &quot;metric value ==&nbsp; &quot; &lt;&lt; value &lt;&lt; std::endl;<br>&nbsp; std::cout &lt;&lt; &quot;displacement = &quot; &lt;&lt; displacement &lt;&lt; std::endl;</p>
<p>&nbsp; return 0;<br>}<br></p></div><span></span><br clear="all">