[Insight-users] On MultiResolutionImageRegistrationMethod

Sri Valli valli_gummadi@yahoo.co.in
Sat, 1 Feb 2003 13:41:33 +0000 (GMT)


--0-755963147-1044106893=:68970
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Hi Lydia,

     Thanks for ur suggestions. Well i could correct the problem which was coming before. Now again i face problem on rotation. This example MultiResImageRegistration2.cxx is not working for registering with a rotated image. I have pasted my code at the end of this mail. Please go through the code and send me the code which have to be added to it or to be modified. I am using a data set of (256 x 256 x 1). The pixel values are from 0 to 120. I have rotated the image in z-direction with angle 10 degrees. I gave this rotated image as moving image and normal image as fixed image to the application with code below. Please go through it and send me the missing code.

    Thanks in advance.

-Regards,
   Sateesh.

 

My code......Follows.....

  if( argc < 3 )
    {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " fixedImageFile  movingImageFile ";
    std::cerr << " outputImagefile"     << std::endl;
    return 1;
    }
  
  const    unsigned int    Dimension = 2;
  typedef  unsigned short  PixelType;
  
  typedef itk::Image< PixelType, Dimension >  FixedImageType;
  typedef itk::Image< PixelType, Dimension >  MovingImageType;

  typedef   float     InternalPixelType;

  typedef itk::AffineTransform< double, Dimension > TransformType;
  // Software Guide : EndCodeSnippet

 

  typedef itk::RegularStepGradientDescentOptimizer       OptimizerType;
  typedef itk::LinearInterpolateImageFunction< 
                                    InternalImageType,
                                    double             > InterpolatorType;
  typedef itk::MattesMutualInformationImageToImageMetric< 
                                          InternalImageType, 
                                          InternalImageType >    MetricType;

  typedef OptimizerType::ScalesType       OptimizerScalesType;


  typedef itk::MultiResolutionImageRegistrationMethod< 
                                    InternalImageType, 
                                    InternalImageType    > RegistrationType;

  typedef itk::RecursiveMultiResolutionPyramidImageFilter<
                                    InternalImageType,
                                    InternalImageType  >    FixedImagePyramidType;

 
  typedef itk::RecursiveMultiResolutionPyramidImageFilter<
                                    InternalImageType,
                                    InternalImageType  >   MovingImagePyramidType;


  OptimizerType::Pointer      optimizer     = OptimizerType::New();
  InterpolatorType::Pointer   interpolator  = InterpolatorType::New();
  RegistrationType::Pointer   registration  = RegistrationType::New();
  MetricType::Pointer         metric        = MetricType::New();

  registration->SetOptimizer(     optimizer     );
  registration->SetInterpolator(  interpolator  );
  registration->SetMetric( metric  );

  std::cout << "\n Set :: Optimizer, interpolator, metric ";
  
  TransformType::Pointer   transform  = TransformType::New();

  registration->SetTransform( transform );
   // Software Guide : EndCodeSnippet


  std::cout << "\n Set :: Transform ";

 

 

  FixedImagePyramidType::Pointer fixedImagePyramid = 
      FixedImagePyramidType::New();

  MovingImagePyramidType::Pointer movingImagePyramid =
      MovingImagePyramidType::New();


  typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
  typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;

  FixedImageReaderType::Pointer  fixedImageReader  = FixedImageReaderType::New();
  MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();

  fixedImageReader->SetFileName(  argv[1] );
  movingImageReader->SetFileName( argv[2] );

  int nx = 256, ny = 256, nz = 5;

  typedef  itk::RawImageIO<PixelType,Dimension>   RawReaderType;
  RawReaderType::Pointer  rawReader  = RawReaderType::New();
  rawReader->SetDimensions( 0, nx );
  rawReader->SetDimensions( 1, ny );
 // rawReader->SetDimensions( 2, nz );


  fixedImageReader->SetImageIO( rawReader );

  try
  {
    fixedImageReader->Update();
  }
  catch( itk::ExceptionObject & e )
  {
    std::cerr << "Exception caught during Raw file reading " << std::endl;
    std::cerr << e << std::endl;
    return -1;
  }


  movingImageReader->SetImageIO( rawReader );

  try
  {
   movingImageReader->Update();
  }
  catch( itk::ExceptionObject & e )
  {
    std::cerr << "Exception caught during Raw file reading " << std::endl;
    std::cerr << e << std::endl;
    return -1;
  }


  std::cout << "\n First file : " << argv[1] << std::endl;
  std::cout << "Second file : " << argv[2] << std::endl;


  typedef itk::CastImageFilter< 
                        FixedImageType, InternalImageType > FixedCastFilterType;
  
  typedef itk::CastImageFilter< 
                        MovingImageType, InternalImageType > MovingCastFilterType;

  FixedCastFilterType::Pointer fixedCaster   = FixedCastFilterType::New();

  MovingCastFilterType::Pointer movingCaster = MovingCastFilterType::New();

  fixedCaster->SetInput(  fixedImageReader->GetOutput() );

  std::cout << "\n\n Set Fixed Caster";

  movingCaster->SetInput( movingImageReader->GetOutput() );
  
  std::cout << "\n\n Set Moving Caster";

  registration->SetFixedImage(    fixedCaster->GetOutput()    );
  std::cout << "\n\n SetFixedImage";

  registration->SetMovingImage(   movingCaster->GetOutput()   );
  std::cout << "\n\n SetMovingImage";


  fixedCaster->Update();
  std::cout << "\n\n Update";

  registration->SetFixedImageRegion(fixedCaster->GetOutput()->GetBufferedRegion() );

  std::cout << "\n\n SetFixedImageRegion";
   
 transform->SetIdentity();

 registration->SetInitialTransformParameters( transform->GetParameters() );
 OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );

  std::cout << "\nGet No of Params : " << transform->GetNumberOfParameters() << std::endl;

  optimizerScales[0] = 1.0;// / 100.0; // scale for M11
  optimizerScales[1] = 1.0;// / 100.0; // scale for M12
  optimizerScales[2] = 1.0;// / 100.0; // scale for M21
  optimizerScales[3] = 1.0;// / 100.0; // scale for M22
  typedef itk::Image< InternalPixelType, Dimension > InternalImageType;

 optimizerScales[4] = 1.0 / 1000000.0; // scale for translation on Y
  optimizerScales[5] = 1.0 / 1000000.0; // scale for translation on Z
 optimizer->SetScales( optimizerScales );
 metric->SetNumberOfHistogramBins( 50 );
  metric->SetNumberOfSpatialSamples( 1000 );
 optimizer->SetNumberOfIterations(    200   );
 CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
  optimizer->AddObserver( itk::IterationEvent(), observer );
 typedef RegistrationInterfaceCommand<RegistrationType> CommandType;

  CommandType::Pointer command = CommandType::New();
  registration->AddObserver( itk::IterationEvent(), command );

 

  registration->SetNumberOfLevels( 3 );


  std::cout << "\n Before Registration ";

  try 
    { 
    registration->StartRegistration(); 
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return -1;
    } 


  std::cout << "Hello";

  typedef RegistrationType::ParametersType ParametersType;
  ParametersType finalParameters = registration->GetLastTransformParameters();
  
  double TranslationAlongX = finalParameters[4];
  double TranslationAlongY = finalParameters[5];
  
  unsigned int numberOfIterations = optimizer->GetCurrentIteration();
  
  double bestValue = optimizer->GetValue();

  
  //
  // Print out results
  //
  std::cout << "Result = " << std::endl;
  std::cout << " Translation X = " << TranslationAlongX  << std::endl;
  std::cout << " Translation Y = " << TranslationAlongY  << std::endl;
  std::cout << " Iterations    = " << numberOfIterations << std::endl;
  std::cout << " Metric value  = " << bestValue          << std::endl;
typedef itk::ResampleImageFilter< 
                            MovingImageType, 
                            FixedImageType >    ResampleFilterType;

  TransformType::Pointer finalTransform = TransformType::New();

  finalTransform->SetParameters( finalParameters );

  finalTransform->PrintSelf(std::cout,NULL);

  ResampleFilterType::Pointer resample = ResampleFilterType::New();

  resample->SetTransform( finalTransform );
  resample->SetInput( movingImageReader->GetOutput() );

  FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();

  resample->SetSize(    fixedImage->GetLargestPossibleRegion().GetSize() );
  resample->SetOutputOrigin(  fixedImage->GetOrigin() );
  resample->SetOutputSpacing( fixedImage->GetSpacing() );
  resample->SetDefaultPixelValue( 100 );


  typedef  short  OutputPixelType;

  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  
  typedef itk::CastImageFilter< 
                        FixedImageType,
                        OutputImageType > CastFilterType;
                    
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;


  WriterType::Pointer      writer =  WriterType::New();
  CastFilterType::Pointer  caster =  CastFilterType::New();


  writer->SetFileName( argv[3] );

  std::cout << "\n OutPut : " << argv[3] << std::endl;
  

  caster->SetInput( resample->GetOutput() );
  writer->SetInput( caster->GetOutput()   );
  writer->SetImageIO(rawReader);

  std::cout << "\n Writer : SetInput, SetImageIO";

  try
 {
  writer->Write();
  std::cout << "\n Write()";
 }
  catch( itk::ExceptionObject & e )
    {
    std::cerr << "Exception caught during Raw file writing " << std::endl;
    std::cerr << e << std::endl;
    return -1;
    }

  std::cout << "File succesfully writen ! " << std::endl;


Catch all the cricket action. Download Yahoo! Score tracker
--0-755963147-1044106893=:68970
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<P>Hi Lydia,</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; Thanks for ur suggestions. Well i could correct the problem which was coming before. Now again i face problem on rotation. This example MultiResImageRegistration2.cxx is not working for registering with a rotated image. I have pasted my code at the end of this mail. Please go through the code and send me the code which have to be added to it or to be modified. I am using a data set of (256 x 256 x 1). The pixel values are from 0 to 120. I have rotated the image in z-direction with angle 10 degrees. I gave this rotated image as moving image and normal image as fixed image to the application with code below. Please go through it and send me the missing code.</P>
<P>&nbsp;&nbsp;&nbsp; Thanks in advance.</P>
<P>-Regards,<BR>&nbsp;&nbsp; Sateesh.</P>
<P>&nbsp;</P>
<P>My code......Follows.....</P>
<P>&nbsp; if( argc &lt; 3 )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Missing Parameters " &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Usage: " &lt;&lt; argv[0];<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; " fixedImageFile&nbsp; movingImageFile ";<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; " outputImagefile"&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; return 1;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; <BR>&nbsp; const&nbsp;&nbsp;&nbsp; unsigned int&nbsp;&nbsp;&nbsp; Dimension = 2;<BR>&nbsp; typedef&nbsp; unsigned short&nbsp; PixelType;<BR>&nbsp; <BR>&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp; FixedImageType;<BR>&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp; MovingImageType;</P>
<P>&nbsp; typedef&nbsp;&nbsp; float&nbsp;&nbsp;&nbsp;&nbsp; InternalPixelType;</P>
<P>&nbsp; typedef itk::AffineTransform&lt; double, Dimension &gt; TransformType;<BR>&nbsp; // Software Guide : EndCodeSnippet</P>
<P>&nbsp;</P>
<P>&nbsp; typedef itk::RegularStepGradientDescentOptimizer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OptimizerType;<BR>&nbsp; typedef itk::LinearInterpolateImageFunction&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;&nbsp;&nbsp;&nbsp; InternalImageType,<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;&nbsp;&nbsp;&nbsp; double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt; InterpolatorType;<BR>&nbsp; typedef itk::MattesMutualInformationImageToImageMetric&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalImageType, <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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalImageType &gt;&nbsp;&nbsp;&nbsp; MetricType;</P>
<P>&nbsp; typedef OptimizerType::ScalesType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OptimizerScalesType;</P>
<P><BR>&nbsp; typedef itk::MultiResolutionImageRegistrationMethod&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;&nbsp;&nbsp;&nbsp; InternalImageType, <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;&nbsp;&nbsp;&nbsp; InternalImageType&nbsp;&nbsp;&nbsp; &gt; RegistrationType;</P>
<P>&nbsp; typedef itk::RecursiveMultiResolutionPyramidImageFilter&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;&nbsp;&nbsp;&nbsp; InternalImageType,<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;&nbsp;&nbsp;&nbsp; InternalImageType&nbsp; &gt;&nbsp;&nbsp;&nbsp; FixedImagePyramidType;</P>
<P>&nbsp;<BR>&nbsp; typedef itk::RecursiveMultiResolutionPyramidImageFilter&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;&nbsp;&nbsp;&nbsp; InternalImageType,<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;&nbsp;&nbsp;&nbsp; InternalImageType&nbsp; &gt;&nbsp;&nbsp; MovingImagePyramidType;</P>
<P><BR>&nbsp; OptimizerType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; optimizer&nbsp;&nbsp;&nbsp;&nbsp; = OptimizerType::New();<BR>&nbsp; InterpolatorType::Pointer&nbsp;&nbsp; interpolator&nbsp; = InterpolatorType::New();<BR>&nbsp; RegistrationType::Pointer&nbsp;&nbsp; registration&nbsp; = RegistrationType::New();<BR>&nbsp; MetricType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; metric&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = MetricType::New();</P>
<P>&nbsp; registration-&gt;SetOptimizer(&nbsp;&nbsp;&nbsp;&nbsp; optimizer&nbsp;&nbsp;&nbsp;&nbsp; );<BR>&nbsp; registration-&gt;SetInterpolator(&nbsp; interpolator&nbsp; );<BR>&nbsp; registration-&gt;SetMetric( metric&nbsp; );</P>
<P>&nbsp; std::cout &lt;&lt; "\n Set :: Optimizer, interpolator, metric ";<BR>&nbsp; <BR>&nbsp; TransformType::Pointer&nbsp;&nbsp; transform&nbsp; = TransformType::New();</P>
<P>&nbsp; registration-&gt;SetTransform( transform );<BR>&nbsp;&nbsp; // Software Guide : EndCodeSnippet</P>
<P><BR>&nbsp; std::cout &lt;&lt; "\n Set :: Transform ";</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp; FixedImagePyramidType::Pointer fixedImagePyramid = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FixedImagePyramidType::New();</P>
<P>&nbsp; MovingImagePyramidType::Pointer movingImagePyramid =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MovingImagePyramidType::New();</P>
<P><BR>&nbsp; typedef itk::ImageFileReader&lt; FixedImageType&nbsp; &gt; FixedImageReaderType;<BR>&nbsp; typedef itk::ImageFileReader&lt; MovingImageType &gt; MovingImageReaderType;</P>
<P>&nbsp; FixedImageReaderType::Pointer&nbsp; fixedImageReader&nbsp; = FixedImageReaderType::New();<BR>&nbsp; MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();</P>
<P>&nbsp; fixedImageReader-&gt;SetFileName(&nbsp; argv[1] );<BR>&nbsp; movingImageReader-&gt;SetFileName( argv[2] );</P>
<P>&nbsp; int nx = 256, ny = 256, nz = 5;</P>
<P>&nbsp; typedef&nbsp; itk::RawImageIO&lt;PixelType,Dimension&gt;&nbsp;&nbsp; RawReaderType;<BR>&nbsp; RawReaderType::Pointer&nbsp; rawReader&nbsp; = RawReaderType::New();<BR>&nbsp; rawReader-&gt;SetDimensions( 0, nx );<BR>&nbsp; rawReader-&gt;SetDimensions( 1, ny );<BR>&nbsp;// rawReader-&gt;SetDimensions( 2, nz );</P>
<P><BR>&nbsp; fixedImageReader-&gt;SetImageIO( rawReader );</P>
<P>&nbsp; try<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; fixedImageReader-&gt;Update();<BR>&nbsp; }<BR>&nbsp; catch( itk::ExceptionObject &amp; e )<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Exception caught during Raw file reading " &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp; }</P>
<P><BR>&nbsp; movingImageReader-&gt;SetImageIO( rawReader );</P>
<P>&nbsp; try<BR>&nbsp; {<BR>&nbsp;&nbsp; movingImageReader-&gt;Update();<BR>&nbsp; }<BR>&nbsp; catch( itk::ExceptionObject &amp; e )<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Exception caught during Raw file reading " &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp; }</P>
<P><BR>&nbsp; std::cout &lt;&lt; "\n First file : " &lt;&lt; argv[1] &lt;&lt; std::endl;<BR>&nbsp; std::cout &lt;&lt; "Second file : " &lt;&lt; argv[2] &lt;&lt; std::endl;</P>
<P><BR>&nbsp; typedef itk::CastImageFilter&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; FixedImageType, InternalImageType &gt; FixedCastFilterType;<BR>&nbsp; <BR>&nbsp; typedef itk::CastImageFilter&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; MovingImageType, InternalImageType &gt; MovingCastFilterType;</P>
<P>&nbsp; FixedCastFilterType::Pointer fixedCaster&nbsp;&nbsp; = FixedCastFilterType::New();</P>
<P>&nbsp; MovingCastFilterType::Pointer movingCaster = MovingCastFilterType::New();</P>
<P>&nbsp; fixedCaster-&gt;SetInput(&nbsp; fixedImageReader-&gt;GetOutput() );</P>
<P>&nbsp; std::cout &lt;&lt; "\n\n Set Fixed Caster";</P>
<P>&nbsp; movingCaster-&gt;SetInput( movingImageReader-&gt;GetOutput() );<BR>&nbsp; <BR>&nbsp; std::cout &lt;&lt; "\n\n Set Moving Caster";</P>
<P>&nbsp; registration-&gt;SetFixedImage(&nbsp;&nbsp;&nbsp; fixedCaster-&gt;GetOutput()&nbsp;&nbsp;&nbsp; );<BR>&nbsp; std::cout &lt;&lt; "\n\n SetFixedImage";</P>
<P>&nbsp; registration-&gt;SetMovingImage(&nbsp;&nbsp; movingCaster-&gt;GetOutput()&nbsp;&nbsp; );<BR>&nbsp; std::cout &lt;&lt; "\n\n SetMovingImage";</P>
<P><BR>&nbsp; fixedCaster-&gt;Update();<BR>&nbsp; std::cout &lt;&lt; "\n\n Update";</P>
<P>&nbsp; registration-&gt;SetFixedImageRegion(fixedCaster-&gt;GetOutput()-&gt;GetBufferedRegion() );</P>
<P>&nbsp; std::cout &lt;&lt; "\n\n SetFixedImageRegion";<BR>&nbsp;&nbsp; <BR>&nbsp;transform-&gt;SetIdentity();</P>
<P>&nbsp;registration-&gt;SetInitialTransformParameters( transform-&gt;GetParameters() );<BR>&nbsp;OptimizerScalesType optimizerScales( transform-&gt;GetNumberOfParameters() );</P>
<P>&nbsp; std::cout &lt;&lt; "\nGet No of Params : " &lt;&lt; transform-&gt;GetNumberOfParameters() &lt;&lt; std::endl;</P>
<P>&nbsp; optimizerScales[0] = 1.0;// / 100.0; // scale for M11<BR>&nbsp; optimizerScales[1] = 1.0;// / 100.0; // scale for M12<BR>&nbsp; optimizerScales[2] = 1.0;// / 100.0; // scale for M21<BR>&nbsp; optimizerScales[3] = 1.0;// / 100.0; // scale for M22<BR>&nbsp; typedef itk::Image&lt; InternalPixelType, Dimension &gt; InternalImageType;</P>
<P>&nbsp;optimizerScales[4] = 1.0 / 1000000.0; // scale for translation on Y<BR>&nbsp; optimizerScales[5] = 1.0 / 1000000.0; // scale for translation on Z<BR>&nbsp;optimizer-&gt;SetScales( optimizerScales );<BR>&nbsp;metric-&gt;SetNumberOfHistogramBins( 50 );<BR>&nbsp; metric-&gt;SetNumberOfSpatialSamples( 1000 );<BR>&nbsp;optimizer-&gt;SetNumberOfIterations(&nbsp;&nbsp;&nbsp; 200&nbsp;&nbsp; );<BR>&nbsp;CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<BR>&nbsp; optimizer-&gt;AddObserver( itk::IterationEvent(), observer );<BR>&nbsp;typedef RegistrationInterfaceCommand&lt;RegistrationType&gt; CommandType;</P>
<P>&nbsp; CommandType::Pointer command = CommandType::New();<BR>&nbsp; registration-&gt;AddObserver( itk::IterationEvent(), command );</P>
<P>&nbsp;</P>
<P>&nbsp; registration-&gt;SetNumberOfLevels( 3 );</P>
<P><BR>&nbsp; std::cout &lt;&lt; "\n Before Registration ";</P>
<P>&nbsp; try <BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp; registration-&gt;StartRegistration(); <BR>&nbsp;&nbsp;&nbsp; } <BR>&nbsp; catch( itk::ExceptionObject &amp; err ) <BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "ExceptionObject caught !" &lt;&lt; std::endl; <BR>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; err &lt;&lt; std::endl; <BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; } </P>
<P><BR>&nbsp; std::cout &lt;&lt; "Hello";</P>
<P>&nbsp; typedef RegistrationType::ParametersType ParametersType;<BR>&nbsp; ParametersType finalParameters = registration-&gt;GetLastTransformParameters();<BR>&nbsp; <BR>&nbsp; double TranslationAlongX = finalParameters[4];<BR>&nbsp; double TranslationAlongY = finalParameters[5];<BR>&nbsp; <BR>&nbsp; unsigned int numberOfIterations = optimizer-&gt;GetCurrentIteration();<BR>&nbsp; <BR>&nbsp; double bestValue = optimizer-&gt;GetValue();</P>
<P>&nbsp; <BR>&nbsp; //<BR>&nbsp; // Print out results<BR>&nbsp; //<BR>&nbsp; std::cout &lt;&lt; "Result = " &lt;&lt; std::endl;<BR>&nbsp; std::cout &lt;&lt; " Translation X = " &lt;&lt; TranslationAlongX&nbsp; &lt;&lt; std::endl;<BR>&nbsp; std::cout &lt;&lt; " Translation Y = " &lt;&lt; TranslationAlongY&nbsp; &lt;&lt; std::endl;<BR>&nbsp; std::cout &lt;&lt; " Iterations&nbsp;&nbsp;&nbsp; = " &lt;&lt; numberOfIterations &lt;&lt; std::endl;<BR>&nbsp; std::cout &lt;&lt; " Metric value&nbsp; = " &lt;&lt; bestValue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; std::endl;<BR>typedef itk::ResampleImageFilter&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; MovingImageType, <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; FixedImageType &gt;&nbsp;&nbsp;&nbsp; ResampleFilterType;</P>
<P>&nbsp; TransformType::Pointer finalTransform = TransformType::New();</P>
<P>&nbsp; finalTransform-&gt;SetParameters( finalParameters );</P>
<P>&nbsp; finalTransform-&gt;PrintSelf(std::cout,NULL);</P>
<P>&nbsp; ResampleFilterType::Pointer resample = ResampleFilterType::New();</P>
<P>&nbsp; resample-&gt;SetTransform( finalTransform );<BR>&nbsp; resample-&gt;SetInput( movingImageReader-&gt;GetOutput() );</P>
<P>&nbsp; FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();</P>
<P>&nbsp; resample-&gt;SetSize(&nbsp;&nbsp;&nbsp; fixedImage-&gt;GetLargestPossibleRegion().GetSize() );<BR>&nbsp; resample-&gt;SetOutputOrigin(&nbsp; fixedImage-&gt;GetOrigin() );<BR>&nbsp; resample-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<BR>&nbsp; resample-&gt;SetDefaultPixelValue( 100 );</P>
<P><BR>&nbsp; typedef&nbsp; short&nbsp; OutputPixelType;</P>
<P>&nbsp; typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<BR>&nbsp; <BR>&nbsp; typedef itk::CastImageFilter&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; FixedImageType,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputImageType &gt; CastFilterType;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp; typedef itk::ImageFileWriter&lt; OutputImageType &gt;&nbsp; WriterType;</P>
<P><BR>&nbsp; WriterType::Pointer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writer =&nbsp; WriterType::New();<BR>&nbsp; CastFilterType::Pointer&nbsp; caster =&nbsp; CastFilterType::New();</P>
<P><BR>&nbsp; writer-&gt;SetFileName( argv[3] );</P>
<P>&nbsp; std::cout &lt;&lt; "\n OutPut : " &lt;&lt; argv[3] &lt;&lt; std::endl;<BR>&nbsp; </P>
<P>&nbsp; caster-&gt;SetInput( resample-&gt;GetOutput() );<BR>&nbsp; writer-&gt;SetInput( caster-&gt;GetOutput()&nbsp;&nbsp; );<BR>&nbsp; writer-&gt;SetImageIO(rawReader);</P>
<P>&nbsp; std::cout &lt;&lt; "\n Writer : SetInput, SetImageIO";</P>
<P>&nbsp; try<BR>&nbsp;{<BR>&nbsp;&nbsp;writer-&gt;Write();<BR>&nbsp;&nbsp;std::cout &lt;&lt; "\n Write()";<BR>&nbsp;}<BR>&nbsp; catch( itk::ExceptionObject &amp; e )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Exception caught during Raw file writing " &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp; std::cout &lt;&lt; "File succesfully writen ! " &lt;&lt; std::endl;<BR></P><p><img src="http://sg.yimg.com/i/aa/icons/28/cricket.gif" height=28 width=28>
Catch all the cricket action. Download <a href="http://in.sports.yahoo.com/cricket/tracker.html" target="_blank">
Yahoo! Score tracker</a>
--0-755963147-1044106893=:68970--