<DIV>Hello,</DIV>
<DIV>The program below is based on registration example and allow an centeredAffineTransform with a iMattesMutualInformation metric...</DIV>
<DIV>I test it with BrainT1SliceBorder20.png and BrainProtonDensitySliceR10X13Y17S12.png. The result is not so bad, but not really good ...</DIV>
<DIV>I think the convergence is to fast ... I think I had to change some parameters but I don't where ....</DIV>
<DIV>Thanks for help</DIV>
<DIV>lagaffe</DIV>
<DIV>-----------------------------------</DIV>
<DIV>Initial Transform Parameters<BR>[1, 0, 0, 1, 110.771, 131.272, -12.3588, -12.3721]<BR>0 -0.494313 [1.03129, 0.0592011, 0.0384303, 1.04259, 110.771, 131.272, -12.3226, -12.3418]<BR>1 -0.506525 [1.01369, 0.0180759, 0.0374976, 1.04872, 110.772, 131.273, -12.3427, -12.3341]<BR>2 -0.497655 [1.01052, 0.00387624, 0.0555589, 1.08858, 110.771, 131.272, -12.3573, -12.3215]<BR>3 -0.476204 [0.985719, -0.0221933, 0.0718157, 1.08991, 110.771, 131.271, -12.3836, -12.3058]<BR>4 -0.46122 [0.952404, -0.0489021, 0.0696406, 1.07258, 110.77, 131.27, -12.4026, -12.3026]<BR>5 -0.46892 [0.951745, -0.0356225, 0.0613028, 1.05532, 110.771, 131.271, -12.3971, -12.3096]<BR>6 -0.476501 [0.942724, -0.0359882, 0.0670168, 1.05927, 110.771, 131.271, -12.4003, -12.3057]<BR>7 -0.476813 [0.934107, -0.0352334, 0.0731064,
1.05942, 110.77, 131.27, -12.4026, -12.2995]<BR>8 -0.481887 [0.9309, -0.0309813, 0.0819638, 1.0591, 110.77, 131.27, -12.4014, -12.2926]<BR>9 -0.485281 [0.927642, -0.0303667, 0.088813, 1.06742, 110.769, 131.269, -12.4017, -12.2872]<BR>10 -0.483528 [0.923046, -0.0309841, 0.0869023, 1.06398, 110.769, 131.27, -12.4023, -12.2885]<BR>11 -0.486905 [0.922546, -0.0292402, 0.0886269, 1.06479, 110.769, 131.269, -12.4015, -12.287]<BR>12 -0.486916 [0.920049, -0.0300743, 0.0896122, 1.06465, 110.769, 131.269, -12.4027, -12.2863]<BR>13 -0.489127 [0.917638, -0.0309204, 0.0903297, 1.06447, 110.769, 131.269, -12.4037, -12.2851]<BR>14 -0.490183 [0.918016, -0.0299934, 0.0909949, 1.06494, 110.769, 131.269, -12.4031, -12.2844]<BR>15 -0.489932 [0.918292, -0.0290254, 0.0916975, 1.06503, 110.769, 131.269, -12.4024,
-12.2837]<BR>Result =<BR> Center X = 110.769<BR> Center Y = 131.269<BR> Translation X = -12.4024<BR> Translation Y = -12.2837<BR> Iterations = 17<BR> Metric value = -0.490452</DIV>
<DIV> </DIV>
<DIV>-----------------------</DIV>
<DIV>source code if someone want it:</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR>#include "itkImageRegistrationMethod.h"<BR>//#include "itkMeanSquaresImageToImageMetric.h"<BR>#include "itkMattesMutualInformationImageToImageMetric.h"<BR>#include "itkLinearInterpolateImageFunction.h"<BR>#include "itkRegularStepGradientDescentOptimizer.h"<BR>#include "itkImage.h"</DIV>
<DIV><BR>#include "itkCenteredTransformInitializer.h"<BR>#include "itkCenteredAffineTransform.h"<BR>#include "itkImageFileReader.h"<BR>#include "itkImageFileWriter.h"</DIV>
<DIV>#include "itkResampleImageFilter.h"<BR>#include "itkCastImageFilter.h"<BR>#include "itkSquaredDifferenceImageFilter.h"<BR>#include "itkCommand.h"<BR>class CommandIterationUpdate : public itk::Command <BR>{<BR>public:<BR> typedef CommandIterationUpdate Self;<BR> typedef itk::Command Superclass;<BR> typedef itk::SmartPointer<Self> Pointer;<BR> itkNewMacro( Self );<BR>protected:<BR> CommandIterationUpdate() {};<BR>public:<BR> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;<BR> typedef const OptimizerType * OptimizerPointer;</DIV>
<DIV> void Execute(itk::Object *caller, const itk::EventObject & event)<BR> {<BR> Execute( (const itk::Object *)caller, event);<BR> }</DIV>
<DIV> void Execute(const itk::Object * object, const itk::EventObject & event)<BR> {<BR> OptimizerPointer optimizer = <BR> dynamic_cast< OptimizerPointer >( object );<BR> if( typeid( event ) != typeid( itk::IterationEvent ) )<BR> {<BR> return;<BR> }<BR> std::cout << optimizer->GetCurrentIteration() << " ";<BR> std::cout << optimizer->GetValue() << " ";<BR> std::cout << optimizer->GetCurrentPosition() << std::endl;<BR> }<BR>};</DIV>
<DIV><BR>int main( int argc, char *argv[] )<BR>{<BR> if( argc < 4 )<BR> {<BR> std::cerr << "Missing Parameters " << std::endl;<BR> std::cerr << "Usage: " << argv[0];<BR> std::cerr << " fixedImageFile movingImageFile " << std::endl;<BR> std::cerr << " outputImagefile [differenceOutputfile] [differenceBeforeRegistration] " << std::endl;<BR> std::cerr << " [stepLength] [maxNumberOfIterations] "<< std::endl;<BR> return 1;<BR> }</DIV>
<DIV> const unsigned int Dimension = 2;<BR> typedef float PixelType;</DIV>
<DIV> typedef itk::Image< PixelType, Dimension > FixedImageType;<BR> typedef itk::Image< PixelType, Dimension > MovingImageType;<BR> <BR> typedef itk::CenteredAffineTransform< <BR> double, <BR> Dimension > TransformType;<BR> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;<BR> /*<BR> typedef itk::MeanSquaresImageToImageMetric<
<BR> FixedImageType, <BR> MovingImageType > MetricType;<BR> */<BR> <BR> typedef itk::MattesMutualInformationImageToImageMetric< <BR> FixedImageType,
<BR> MovingImageType > MetricType;<BR> typedef itk:: LinearInterpolateImageFunction< <BR> MovingImageType,<BR> double > InterpolatorType;<BR> typedef itk::ImageRegistrationMethod<
<BR> FixedImageType, <BR> MovingImageType > RegistrationType;</DIV>
<DIV> MetricType::Pointer metric = MetricType::New();<BR> OptimizerType::Pointer optimizer = OptimizerType::New();<BR> InterpolatorType::Pointer interpolator = InterpolatorType::New();<BR> RegistrationType::Pointer registration = RegistrationType::New();</DIV>
<DIV> registration->SetMetric( metric );<BR> registration->SetOptimizer( optimizer );<BR> registration->SetInterpolator( interpolator );</DIV>
<DIV> metric->SetNumberOfHistogramBins( 50 );<BR> metric->SetNumberOfSpatialSamples( 10000 );</DIV>
<DIV> TransformType::Pointer transform = TransformType::New();<BR> registration->SetTransform( transform );<BR> typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;<BR> typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;<BR> FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();<BR> MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();<BR> fixedImageReader->SetFileName( argv[1] );<BR> movingImageReader->SetFileName( argv[2] );</DIV>
<DIV><BR> registration->SetFixedImage( fixedImageReader->GetOutput() );<BR> registration->SetMovingImage( movingImageReader->GetOutput() );<BR> fixedImageReader->Update();<BR> registration->SetFixedImageRegion( <BR> fixedImageReader->GetOutput()->GetBufferedRegion() );</DIV>
<DIV> typedef itk::CenteredTransformInitializer< <BR> TransformType, <BR> FixedImageType, <BR> MovingImageType > TransformInitializerType;<BR> TransformInitializerType::Pointer initializer = TransformInitializerType::New();<BR> initializer->SetTransform( transform );<BR> initializer->SetFixedImage(
fixedImageReader->GetOutput() );<BR> initializer->SetMovingImage( movingImageReader->GetOutput() );<BR> initializer->MomentsOn();<BR> initializer->InitializeTransform();<BR> std::cout << "Initial Transform Parameters " << std::endl;<BR> std::cout << transform->GetParameters() << std::endl;<BR> <BR>// -----------------------<BR> registration->SetInitialTransformParameters( <BR> transform->GetParameters() );</DIV>
<DIV><BR> double translationScale = 1.0 / 1000.0;<BR> if( argc > 8 )<BR> {<BR> translationScale = atof( argv[8] );<BR> }<BR> typedef OptimizerType::ScalesType OptimizerScalesType;<BR> OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );</DIV>
<DIV> optimizerScales[0] = 0.1;<BR> optimizerScales[1] = 0.1;<BR> optimizerScales[2] = 0.1;<BR> optimizerScales[3] = 0.1;<BR> optimizerScales[4] = translationScale;<BR> optimizerScales[5] = translationScale;<BR> optimizerScales[6] = translationScale;<BR> optimizerScales[7] = translationScale;</DIV>
<DIV> optimizer->SetScales( optimizerScales );<BR> double steplength = 0.1;</DIV>
<DIV> if( argc > 6 )<BR> {<BR> steplength = atof( argv[6] );<BR> }</DIV>
<DIV><BR> unsigned int maxNumberOfIterations = 300;</DIV>
<DIV> if( argc > 7 )<BR> {<BR> maxNumberOfIterations = atoi( argv[7] );<BR> }</DIV>
<DIV> optimizer->SetMaximumStepLength( steplength ); <BR> optimizer->SetMinimumStepLength( 0.001 );<BR> optimizer->SetNumberOfIterations( maxNumberOfIterations );<BR> optimizer->MinimizeOn();</DIV>
<DIV> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<BR> optimizer->AddObserver( itk::IterationEvent(), observer );<BR>try <BR> { <BR> registration->StartRegistration(); <BR> } <BR> catch( itk::ExceptionObject & err ) <BR> { <BR> std::cerr << "ExceptionObject caught !" << std::endl; <BR> std::cerr << err << std::endl; <BR> return -1;<BR> } <BR> OptimizerType::ParametersType finalParameters = <BR> registration->GetLastTransformParameters();</DIV>
<DIV> const double finalRotationCenterX = finalParameters[4];<BR> const double finalRotationCenterY = finalParameters[5];<BR> const double finalTranslationX = finalParameters[6];<BR> const double finalTranslationY = finalParameters[7];</DIV>
<DIV> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();<BR> const double bestValue = optimizer->GetValue();<BR> // Software Guide : EndCodeSnippet</DIV>
<DIV><BR> // Print out results<BR> //<BR> std::cout << "Result = " << std::endl;<BR> std::cout << " Center X = " << finalRotationCenterX << std::endl;<BR> std::cout << " Center Y = " << finalRotationCenterY << std::endl;<BR> std::cout << " Translation X = " << finalTranslationX << std::endl;<BR> std::cout << " Translation Y = " << finalTranslationY << std::endl;<BR> std::cout << " Iterations = " << numberOfIterations << std::endl;<BR> std::cout << " Metric value = " << bestValue << std::endl;<BR> typedef itk::ResampleImageFilter<
<BR> MovingImageType, <BR> FixedImageType > ResampleFilterType;</DIV>
<DIV> TransformType::Pointer finalTransform = TransformType::New();</DIV>
<DIV> finalTransform->SetParameters( finalParameters );</DIV>
<DIV> ResampleFilterType::Pointer resample = ResampleFilterType::New();</DIV>
<DIV> resample->SetTransform( finalTransform );<BR> resample->SetInput( movingImageReader->GetOutput() );</DIV>
<DIV> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();</DIV>
<DIV> resample->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );<BR> resample->SetOutputOrigin( fixedImage->GetOrigin() );<BR> resample->SetOutputSpacing( fixedImage->GetSpacing() );<BR> resample->SetDefaultPixelValue( 100 );<BR> <BR> typedef unsigned char OutputPixelType;</DIV>
<DIV> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<BR> <BR> typedef itk::CastImageFilter< <BR> FixedImageType,<BR> OutputImageType > CastFilterType;<BR> <BR> typedef itk::ImageFileWriter< OutputImageType > WriterType;</DIV>
<DIV><BR> WriterType::Pointer writer = WriterType::New();<BR> CastFilterType::Pointer caster = CastFilterType::New();</DIV>
<DIV><BR> writer->SetFileName( argv[3] );</DIV>
<DIV><BR> caster->SetInput( resample->GetOutput() );<BR> writer->SetInput( caster->GetOutput() );<BR> writer->Update();</DIV>
<DIV><BR> typedef itk::SquaredDifferenceImageFilter< <BR> FixedImageType, <BR> FixedImageType, <BR> OutputImageType > DifferenceFilterType;</DIV>
<DIV> DifferenceFilterType::Pointer difference = DifferenceFilterType::New();</DIV>
<DIV> WriterType::Pointer writer2 = WriterType::New();<BR> writer2->SetInput( difference->GetOutput() ); <BR> </DIV>
<DIV> if( argc > 4 )<BR> {<BR> difference->SetInput1( fixedImageReader->GetOutput() );<BR> difference->SetInput2( resample->GetOutput() );<BR> writer2->SetFileName( argv[4] );<BR> writer2->Update();<BR> }</DIV>
<DIV><BR> if( argc > 5 )<BR> {<BR> writer2->SetFileName( argv[5] );<BR> difference->SetInput1( fixedImageReader->GetOutput() );<BR> difference->SetInput2( movingImageReader->GetOutput() );<BR> writer2->Update();<BR> }</DIV>
<DIV><BR> return 0;<BR>}</DIV>
<DIV> </DIV><p>
                <hr size=1>
Créez gratuitement votre Yahoo! Mail avec <font color="red"><b>100 Mo de stockage !</b></font>
<br><a href="http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=25917/*http://fr.rd.yahoo.com/mail/mail_taglines_100/default/*http://fr.benefits.yahoo.com/">Créez votre Yahoo! Mail</a><br><br>
<font color="red"><b>Le nouveau Yahoo! Messenger est arrivé !</b></font> Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis.
<a href="http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=26111/*http://fr.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com">Téléchargez GRATUITEMENT ici !</a>