hi, <div>Thanks Bill, yes, i didnt think about it :"<div>I tried, there is no exception (in both cases i mentioned in my last post)</div><div><br></div><div>Quyps,</div><div><br></div><div><div><br><div class="gmail_quote">
2009/10/5 Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
The difference could be that the internal values have higher precision<br>
than the printed values.<br>
<br>
You should be getting an exception with the try/catch.<br>
<div><div></div><div class="h5"><br>
<br>
On Sun, Oct 4, 2009 at 1:51 PM, Quy Pham Sy <<a href="mailto:phamsyquybk@gmail.com">phamsyquybk@gmail.com</a>> wrote:<br>
> hi, Bill<br>
> Thanks very much for you help. I tried adding your code. Actually your code<br>
> outputs the metric value to screen, am i right?<br>
> To make all my question clearer<br>
> here is the summary, there're issues:<br>
><br>
> 1 - When I used the output (final transform parameters) from<br>
> ImageRegistration7 example (in ITK source code)<br>
> to reproduce the metric value directly from Metric Object (same as metric<br>
> object type used in ImageRegistration7 example)<br>
> I can not reproduce the same metric value as the example. Why?<br>
><br>
> Output from ImageRegistration7<br>
> -------------------------------------<br>
> Scale = 1.08438<br>
> Angle (radians) 0.154531<br>
> Angle (degrees) 8.85397<br>
> Center X = 170.327<br>
> Center Y = 148.556<br>
> Translation X = -26.6822<br>
> Translation Y = -93.4428<br>
> Iterations = 500<br>
> Metric value = 4551.86<br>
> ---------------------------------------<br>
> Two input image: fixed.bmp; moving.bmp<br>
> Set params code for transformation of metric<br>
> ---------------------------------------------------<br>
> transform->SetScale(1.08438);<br>
> transform->SetAngle(0.154531);<br>
> TransformType::TranslationType translation;<br>
> translation[0] = -26.6822;<br>
> translation[1] = -93.6822;<br>
> transform->SetTranslation(translation);<br>
> MetricType::TransformParametersType transformParams =<br>
> transform->GetParameters();<br>
><br>
> double metricval = metric->GetValue(transformParams);<br>
> /*result: metricval = 4570.285 still != 4551.86*/<br>
> ----------------------------------------------------<br>
><br>
> 2. In theory, the metric value from registration (determined by: transform<br>
> type, metric type, interpolate type) of two images (fixed image, moving<br>
> image) is supposed to be "MINIMUM METRIC VALUE".<br>
> But when i try a set of params (as following) i get a smaller value, event<br>
> down to 0 (still use two input image as above) the value which is impossible<br>
> since two images are not identical !!!<br>
> ----------------------------------------------<br>
> transform->SetScale(0.92632);<br>
> transform->SetAngle(0.15095);<br>
> TransformType::TranslationType translation;<br>
> translation[0] = 28.29828;<br>
> translation[1] = 94.07266;<br>
> transform->SetTranslation(translation);<br>
> MetricType::TransformParametersType transformParams =<br>
> transform->GetParameters();<br>
><br>
> double metricval = metric->GetValue(transformParams);<br>
> /*result: metricval == 0 !!!! */<br>
> -------------------------------------------------<br>
> Really appreciate any suggest and help!<br>
> //========================================================================<br>
> // HERE IS THE SOURCE CODE TO REPRODUCE THESE PROBLEMS<br>
> //========================================================================<br>
> int main( int argc, char * argv[] )<br>
> {<br>
> const unsigned int Dimension = 2;<br>
> typedef unsigned char PixelType;<br>
> typedef itk::Image< PixelType, Dimension > ImageType;<br>
> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
> ReaderType::Pointer fixedReader = ReaderType::New();<br>
> ReaderType::Pointer movingReader = ReaderType::New();<br>
> fixedReader->SetFileName( "fixed.bmp" );<br>
> movingReader->SetFileName( "moving.bmp" );<br>
><br>
> try<br>
> {<br>
> fixedReader->Update();<br>
> movingReader->Update();<br>
> }<br>
> catch( itk::ExceptionObject & excep )<br>
> {<br>
> std::cerr << "Exception catched !" << std::endl;<br>
> std::cerr << excep << std::endl;<br>
> }<br>
><br>
> typedef itk::MeanSquaresImageToImageMetric< ImageType, ImageType ><br>
> MetricType;<br>
> MetricType::Pointer metric = MetricType::New();<br>
> typedef itk::CenteredSimilarity2DTransform < double > TransformType;<br>
> TransformType::Pointer transform = TransformType::New();<br>
> typedef itk::LinearInterpolateImageFunction< ImageType, double ><br>
> InterpolatorType;<br>
> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
> ImageType::Pointer fixedImage = fixedReader->GetOutput();<br>
> ImageType::Pointer movingImage = movingReader->GetOutput();<br>
> typedef itk::CenteredTransformInitializer< TransformType, ImageType,<br>
> ImageType > TransformInitializerType;<br>
> TransformInitializerType::Pointer initializer =<br>
> TransformInitializerType::New();<br>
> initializer->SetTransform( transform );<br>
> initializer->SetFixedImage( fixedImage );<br>
> initializer->SetMovingImage( movingImage );<br>
> initializer->MomentsOn();<br>
> initializer->InitializeTransform();<br>
> metric->SetTransform( transform );<br>
> metric->SetInterpolator( interpolator );<br>
> metric->SetFixedImage( fixedImage );<br>
> metric->SetMovingImage( movingImage );<br>
> metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );<br>
> try<br>
> {<br>
> metric->Initialize();<br>
> }<br>
> catch( itk::ExceptionObject & excep )<br>
> {<br>
> std::cerr << "Exception catched !" << std::endl;<br>
> std::cerr << excep << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
> //************************************************************************/<br>
> // CHANGE PARAMETERS HERE TO REPRODUCE PROBLEM<br>
> transform->SetScale(0.92632);<br>
> transform->SetAngle(0.15095);<br>
> TransformType::TranslationType translation;<br>
> translation[0] = 28.29828;<br>
> translation[1] = 94.07266;<br>
><br>
> //*************************************************************************/<br>
><br>
> transform->SetTranslation(translation);<br>
> MetricType::TransformParametersType transformParams =<br>
> transform->GetParameters();<br>
> double metricval = 0.0;<br>
> try<br>
> {<br>
> metricval = metric->GetValue(transformParams);<br>
> std::cout << "metricval: " << metricval << std::endl;<br>
> }<br>
> catch( itk::ExceptionObject & excep )<br>
> {<br>
> std::cerr << "Exception catched !" << std::endl;<br>
> std::cerr << excep << std::endl;<br>
> std::cout << "metricval: " << metricval << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
> return EXIT_SUCCESS;<br>
> }<br>
> =======================================================================================<br>
><br>
</div></div></blockquote></div><br>
</div></div></div>