[Insight-users] Registration binary images
Luis Ibanez
luis.ibanez at kitware.com
Sat Oct 24 16:08:35 EDT 2009
Hi Serena,
Is there a chance that you could share your images ?
It will be a lot easier for us to run a registration locally
using your images, and to fine tune the optimization
parameters than to track this by email.
Please let us know
Thanks
Luis
-------------------------------------------------------------
On Thu, Oct 22, 2009 at 2:55 PM, Serena Fabbri <fabbri at u.washington.edu> wrote:
> Hi Luise and All,
>
> I have tuned fine the parameters and now my Affine Registration works.
> I am trying to enlarge the moving image, and i have set
>
> scaling[0]=1.5; scaling[1]=1.01; scaling[2]=1.;
> transform->Scale( scaling, true );
>
> but the registration is not good.
> Are there any strategies to set scaling and shear to obtain a good deformed
> image?
>
> Thank you for any suggestion.
>
> Serena.
>
>
>
> On Tue, 20 Oct 2009, Luis Ibanez wrote:
>
>> Hi Serena,
>>
>> You want to fine tune the following parameters:
>>
>> optimizer->SetParametersConvergenceTolerance( 0.25 ); // quarter pixel
>> optimizer->SetFunctionConvergenceTolerance(0.1); // 0.1%
>>
>>
>> You probably copy them from the example ImageRegistration10.cxx.
>>
>>
>> They were fine for a TranslationTransform, but they are not good
>> for an AffineTransform.
>>
>> This is because the dynamic range of the rotation parameters
>> is proportional to radians (and scaling), and a step of 0.25 is
>> enormous in that space.
>>
>> For your convenience, we just added a new example to the repository,
>> illustrating how to perform registration using the AffineTransform.
>>
>> This new Example is
>>
>> Insight/Examples/Registration/ImageRegistration19.cxx
>>
>> it is based on ImageRegistration10.cxx.
>>
>> We replaced the TranslationTransform with an AffineTransform,
>> added a CenteredTransformInitializer and fine tunned the convergence
>> parameters of the AmoebaOptimizers.
>>
>> You will find this new example at:
>>
>> http://public.kitware.com/cgi-bin/viewcvs.cgi/Examples/Registration/ImageRegistration19.cxx?
>
> root=Insight&sortby=date&view=log
>>
>> You could get the source code by clicking on the "download" link,
>> or by updating your CVS checkout of ITK (if you have one).
>>
>> A test has been defined for this example.
>>
>> You can run it with:
>>
>> ctest -R ImageRegistration19 -V
>>
>>
>>
>> Please give it a try and let us know if you find any problems,
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>>
>> -----------------------------------------------------------------------
>> On Fri, Oct 16, 2009 at 9:17 PM, Serena Fabbri <fabbri at u.washington.edu>
>> wrote:
>>>
>>> Hi All,
>>>
>>> I am registering binary images with Affine Transformation,
>>> MatchCardinality
>>> Metric, Amoeba optimizer, NearestNeighbor Interpolator.
>>> When I set optimizerScales with SetScales( optimizerScales ), I obtain
>>> this
>>> message independently by chosen values.
>>>
>>> ExceptionObject caught !
>>>
>>> itk::ExceptionObject (0x66d6a0)
>>> Location: "typename itk::MatchCardinalityImageToImageMetric<TFixedImage,
>>> TMovingImage>::MeasureType
>>> itk::MatchCardinalityImageToImageMetric<TFixedImage,
>>> TMovingImage>::GetNonconstValue(const typename
>>> itk::ImageToImageMetric<TFixedImage,
>>> TMovingImage>::TransformParametersType&) [with TFixedImage = main(int,
>>> char**)::FixedImageType, TMovingImage = main(int,
>>> char**)::MovingImageType]"
>>> File: /Users/physics/InsightToolkit-
>>> 3.10.0/Code/Algorithms/itkMatchCardinalityImageToImageMetric.txx
>>> Line: 130
>>> Description: itk::ERROR: MatchCardinalityImageToImageMetric(0x6690c0):
>>> All
>>> the points mapped to outside of the moving image
>>>
>>>
>>>
>>> If I don't set optimizerScales the registration starts but I have another
>>> problem.
>>> I visualize the registration task with an observer with these 2
>>> instruction:
>>> std::cout << optimizer->GetCachedCurrentPosition()<< " ";
>>> std::cout << optimizer->GetCachedValue() ;
>>>
>>> and it seems work but when I call
>>> OptimizerType::ParametersType finalParameters =
>>> registration->GetLastTransformParameters();
>>> I get the initial parameters, so the output image is not registered.
>>>
>>> does anyone experience with Affine Registration of binary image?
>>> Could you give me any suggestion?
>>> Thank you for any advice.
>>> Serena.
>>>
>>>
>>> this is the code:
>>>
>>>
>>>
>>>
>>> // Metric
>>>
>>> metric->MeasureMatchesOff();
>>>
>>> // Transform
>>> TransformInitializerType::Pointer initializer =
>>> TransformInitializerType::New();
>>> initializer->SetTransform( transform );
>>> initializer->SetFixedImage( fixedImageReader->GetOutput() );
>>> initializer->SetMovingImage( movingImageReader->GetOutput() );
>>> initializer->GeometryOn();
>>> initializer->InitializeTransform();
>>>
>>>
>>> //Optimizer
>>> unsigned int maxNumberOfIterations = 2000;
>>>
>>> if( argc > 3 )
>>> {
>>> maxNumberOfIterations = atoi( argv[4] );
>>> }
>>>
>>> OptimizerType::ParametersType
>>> simplexDelta( transform->GetNumberOfParameters() );
>>> simplexDelta.Fill( 10.0 );
>>> std::cout<<"simplexDelta "<<simplexDelta<<std::endl;
>>> std::cout<<"GetScales() "<<optimizer->GetScales()<<std::endl;
>>> typedef OptimizerType::ScalesType OptimizerScalesType;
>>> OptimizerScalesType optimizerScales(
>>> transform->GetNumberOfParameters() );
>>>
>>> optimizerScales[0] = 1.000;
>>> optimizerScales[1] = 1.000;
>>> optimizerScales[2] = 1.000;
>>>
>>> optimizerScales[3] = 1.000;
>>> optimizerScales[4] = 1.000;
>>> optimizerScales[5] = 1.000;
>>>
>>> optimizerScales[6] = 1.000;
>>> optimizerScales[7] = 1.000;
>>> optimizerScales[8] = 1.000;
>>>
>>> double translationScale = 1.000;
>>> optimizerScales[9] = translationScale;
>>> optimizerScales[10] = translationScale;
>>> optimizerScales[11] = translationScale;
>>>
>>> optimizer->SetScales( optimizerScales );
>>> std::cout<<"GetScales() "<<optimizer->GetScales()<<std::endl;
>>> optimizer->AutomaticInitialSimplexOff();
>>> optimizer->SetInitialSimplexDelta( simplexDelta );
>>> optimizer->SetParametersConvergenceTolerance( 0.25 ); // quarter
>>> pixel
>>> optimizer->SetFunctionConvergenceTolerance(0.1); // 0.1%
>>> optimizer->SetMaximumNumberOfIterations(maxNumberOfIterations );
>>>
>>> //Registration
>>> registration->SetMetric(
>>> metric );
>>> registration->SetOptimizer(
>>> optimizer );
>>> registration->SetInterpolator(
>>> interpolator );
>>> registration->SetTransform(
>>> transform );
>>> registration->SetFixedImage(
>>> fixedImageReader->GetOutput() );
>>> registration->SetMovingImage(
>>> movingImageReader->GetOutput() );
>>> registration->SetFixedImageRegion(
>>> fixedImageReader->GetOutput()-
>>>>
>>>> GetBufferedRegion() );
>>>
>>> registration->SetInitialTransformParameters(
>>> transform->GetParameters() );
>>>
>>> // Osservatori
>>> itkProbesCreate();
>>> CommandIterationUpdate::Pointer observer =
>>> CommandIterationUpdate::New();
>>> optimizer->AddObserver( itk::IterationEvent(), observer);
>>>
>>> std::cout << std::endl << "Starting Affine Registration " << std::endl;
>>> std::cout << transform->GetNumberOfParameters()<< " " <<
>>> transform-
>>>>
>>>> GetParameters()<<std::endl;
>>>
>>> try
>>> {
>>> registration->Initialize();
>>> std::cout << "Initial Metric value = "<<
>>> metric->GetValue(transform-
>>>>
>>>> GetNumberOfParameters() ) << std::endl;
>>>
>>> itkProbesStart( "Affine Registration " );
>>> registration->StartRegistration();
>>> itkProbesStop( "Affine Registration " );
>>> }
>>> catch( itk::ExceptionObject & err )
>>> {
>>> std::cerr << "ExceptionObject caught !" << std::endl;
>>> std::cerr << err << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>> // Report the time and memory taken by the registration
>>> itkProbesReport( std::cout );
>>>
>>>
>>> std::cout << "Affine Registration completed" << std::endl;
>>> std::cout << std::endl;
>>>
>>>
>>>
>>>
>>> OptimizerType::ParametersType finalParameters =
>>> registration->GetLastTransformParameters();
>>>
>>> const double finalRotationCenterX = transform->GetCenter()[0];
>>> const double finalRotationCenterY = transform->GetCenter()[1];
>>> const double finalRotationCenterZ = transform->GetCenter()[2];
>>> const double finalTranslationX = finalParameters[9];
>>> const double finalTranslationY = finalParameters[10];
>>> const double finalTranslationZ = finalParameters[11];
>>>
>>> const unsigned int numberOfIterations =
>>> optimizer->GetOptimizer()->get_num_evaluations();
>>> const double bestValue = optimizer->GetValue();
>>>
>>>
>>>
>>> // Print out results
>>>
>>> std::cout << "Result = " << std::endl;
>>> std::cout << " Center X = " << finalRotationCenterX <<
>>> std::endl;
>>> std::cout << " Center Y = " << finalRotationCenterY <<
>>> std::endl;
>>> std::cout << " Center Z = " << finalRotationCenterZ <<
>>> std::endl;
>>> std::cout << " Translation X = " << finalTranslationX <<
>>> std::endl;
>>> std::cout << " Translation Y = " << finalTranslationY <<
>>> std::endl;
>>> std::cout << " Translation Z = " << finalTranslationZ <<
>>> std::endl;
>>> std::cout << " Iterations = " << numberOfIterations <<
>>> std::endl;
>>> std::cout << " Metric value = " << bestValue <<
>>> std::endl;
>>> std::cout << " finalParameters = "<<finalParameters<<std::endl;
>>> std::cout << " finalParameters =
>>> "<<transform->GetParameters()<<std::endl;
>>>
>>> //write time
>>> TransformType::Pointer finalTransform = TransformType::New();
>>>
>>> finalTransform->SetCenter( transform->GetCenter() );
>>> finalTransform->SetParameters( finalParameters );
>>> resampler->SetTransform( finalTransform );
>>> resampler->SetInput( movingImageReader->GetOutput() );
>>>
>>> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
>>>
>>> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize()
>>> );
>>> resampler->SetOutputOrigin( fixedImage->GetOrigin() );
>>> resampler->SetOutputSpacing( fixedImage->GetSpacing() );
>>> resampler->SetOutputDirection( fixedImage->GetDirection() );
>>> resampler->SetDefaultPixelValue( 0 );
>>>
>>>
>>>
>>>
>>> writer->SetFileName( argv[3] );
>>> caster->SetInput( resampler->GetOutput() );
>>> writer->SetInput( caster->GetOutput() );
>>>
>>>
>>> try
>>> {
>>> writer->Update();
>>> }
>>> catch( itk::ExceptionObject & err )
>>> {
>>> std::cerr << "ExceptionObject caught !" << std::endl;
>>> std::cerr << err << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>
>
>
>
>
More information about the Insight-users
mailing list