hi, Bill<div><br></div><div>Thanks very much for you help. I tried adding your code. Actually your code outputs the metric value to screen, am i right?</div><div><br></div><div>To make all my question clearer </div><div>here is the summary, there're issues: </div>
<div><br></div><div><br></div><div>1 - When I used the output (final transform parameters) from ImageRegistration7 example (in ITK source code) </div><div>to reproduce the metric value directly from Metric Object (same as metric object type used in ImageRegistration7 example) </div>
<div>I can not reproduce the same metric value as the example. Why? </div><div><br></div><div><br></div><div>Output from ImageRegistration7 </div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px; border-collapse: collapse; ">-------------------------------------</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px; border-collapse: collapse; "><div><div> Scale = 1.08438</div><div> Angle (radians) 0.154531</div><div> Angle (degrees) 8.85397</div>
<div> Center X = 170.327</div><div> Center Y = 148.556</div><div> Translation X = -26.6822</div><div> Translation Y = -93.4428</div><div> Iterations = 500</div><div> Metric value = 4551.86</div><div>---------------------------------------</div>
</div></span></div><div><br></div><div>Two input image: <span class="Apple-style-span" style="font-family: Arial; font-size: 10px; border-collapse: collapse; color: rgb(102, 102, 102); white-space: pre; "><a href="http://picasaweb.google.com/lh/photo/qq5iA-PTGX6o3ZtslBX5HQ?authkey=Gv1sRgCPfxyPeBwITjkwE&feat=directlink" target="_blank" style="color: rgb(87, 151, 176); ">fixed.bmp</a>; <a href="http://picasaweb.google.com/phamsyquybk/DropBox?authkey=Gv1sRgCPfxyPeBwITjkwE#5388585730742727138" target="_blank" style="color: rgb(87, 151, 176); ">moving.bmp</a></span></div>
<div><br></div><div><div><span class="Apple-style-span" style="font-size: 12px; "><div>Set params code for transformation of metric</div><div>---------------------------------------------------</div><div><div><span class="Apple-style-span" style="font-size: small; ">transform->SetScale(1.08438);<br>
</span><span class="Apple-style-span" style="font-size: small; ">transform->SetAngle(0.154531);<br></span><span class="Apple-style-span" style="font-size: small; ">TransformType::TranslationType translation;<br></span><span class="Apple-style-span" style="font-size: small; ">translation[0] = -26.6822;<br>
</span><span class="Apple-style-span" style="font-size: small; ">translation[1] = -93.6822;<br></span><span class="Apple-style-span" style="font-size: small; ">transform->SetTranslation(translation);<br></span><span class="Apple-style-span" style="font-size: small; ">MetricType::TransformParametersType transformParams = transform->GetParameters();<br>
</span><span class="Apple-style-span" style="font-size: small; "><br></span></div><div><span class="Apple-style-span" style="font-size: small; ">double metricval = metric->GetValue(transformParams);</span></div><div><span class="Apple-style-span" style="font-size: small; "><br>
</span></div><div><span class="Apple-style-span" style="font-size: small; ">/*result: metricval = <span class="Apple-style-span" style="font-size: 12px; ">4570.285 still != <span class="Apple-style-span" style="font-family: arial, sans-serif; border-collapse: collapse; ">4551.86<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">*/</span></span></span></span></div>
<div>----------------------------------------------------</div></div></span></div><div></div></div><div><br></div><div><br></div><div>2. In theory, the metric value from registration (determined by: transform type, metric type, interpolate type) of two images (fixed image, moving image) is supposed to be "MINIMUM METRIC VALUE". </div>
<div>But when i try a set of params (as following) i get a smaller value, event down to 0 (still use two input image as above) the value which is impossible since two images are not identical !!!</div><div><br></div><div>
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px; border-collapse: collapse; ">----------------------------------------------</span></div><div><span class="Apple-style-span" style="font-size: 12px; "><div>
<span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px; border-collapse: collapse; "><div><div>transform->SetScale(0.92632);</div>
<div>transform->SetAngle(0.15095);</div><div>TransformType::TranslationType translation;</div><div>translation[0] = 28.29828;</div><div>translation[1] = 94.07266;</div><div>transform->SetTranslation(translation);</div>
<div><br></div><div><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; "><div><span class="Apple-style-span" style="font-size: small; ">MetricType::TransformParametersType transformParams = transform->GetParameters();<br>
</span><span class="Apple-style-span" style="font-size: small; "><br></span></div><div><span class="Apple-style-span" style="font-size: small; ">double metricval = metric->GetValue(transformParams);</span></div><div><span class="Apple-style-span" style="font-size: small; "><br>
</span></div><div><span class="Apple-style-span" style="font-size: small; ">/*result: metricval == <span class="Apple-style-span" style="font-size: 12px; ">0 !!!! <span class="Apple-style-span" style="font-family: arial, sans-serif; border-collapse: collapse; "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">*/</span></span></span></span></div>
</span></div><div>-------------------------------------------------</div><div><br></div><div>Really appreciate any suggest and help! </div><div><br></div><div>//========================================================================</div>
<div>// HERE IS THE SOURCE CODE TO REPRODUCE THESE PROBLEMS</div><div>//========================================================================</div><div><div><br></div><div>int main( int argc, char * argv[] )</div>
<div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>const unsigned int Dimension = 2;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef unsigned char PixelType;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::Image< PixelType, Dimension > ImageType;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::ImageFileReader< ImageType > ReaderType;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ReaderType::Pointer fixedReader = ReaderType::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ReaderType::Pointer movingReader = ReaderType::New();</div>
<div><br></div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>fixedReader->SetFileName( "fixed.bmp" );</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>movingReader->SetFileName( "moving.bmp" );</div>
<div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>try </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>fixedReader->Update();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>movingReader->Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>catch( itk::ExceptionObject & excep )</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << "Exception catched !" << std::endl;</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << excep << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::MeanSquaresImageToImageMetric< ImageType, ImageType > MetricType;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>MetricType::Pointer metric = MetricType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::CenteredSimilarity2DTransform < double > TransformType;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>TransformType::Pointer transform = TransformType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::LinearInterpolateImageFunction< ImageType, double > InterpolatorType;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>InterpolatorType::Pointer interpolator = InterpolatorType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ImageType::Pointer fixedImage = fixedReader->GetOutput();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>ImageType::Pointer movingImage = movingReader->GetOutput();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::CenteredTransformInitializer< TransformType, ImageType, ImageType > TransformInitializerType;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>TransformInitializerType::Pointer initializer = TransformInitializerType::New();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>initializer->SetTransform( transform );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>initializer->SetFixedImage( fixedImage );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>initializer->SetMovingImage( movingImage );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>initializer->MomentsOn();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>initializer->InitializeTransform();</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>metric->SetTransform( transform );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>metric->SetInterpolator( interpolator );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>metric->SetFixedImage( fixedImage );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>metric->SetMovingImage( movingImage );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>try </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>metric->Initialize();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>catch( itk::ExceptionObject & excep )</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << "Exception catched !" << std::endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << excep << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//************************************************************************/</div><div>
// CHANGE PARAMETERS HERE TO REPRODUCE PROBLEM</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>transform->SetScale(0.92632);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>transform->SetAngle(0.15095);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>TransformType::TranslationType translation;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>translation[0] = 28.29828;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>translation[1] = 94.07266;</div>
<div> //*************************************************************************/</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>transform->SetTranslation(translation);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>MetricType::TransformParametersType transformParams = transform->GetParameters();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double metricval = 0.0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>try</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>metricval = metric->GetValue(transformParams);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cout << "metricval: " << metricval << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>catch( itk::ExceptionObject & excep )</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << "Exception catched !" << std::endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cerr << excep << std::endl;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>std::cout << "metricval: " << metricval << std::endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>return EXIT_FAILURE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>return EXIT_SUCCESS;</div><div>}</div><div>=======================================================================================</div><div><br></div></div>
</div></span></span></div></span></div>