<div>Hello,</div>
<div> </div>
<div>PROBLEM:</div>
<div> </div>
<div>I am trying to perform registration of two labelled volumes using ITK. </div>
<div> </div>
<div>STUDY:</div>
<div> </div>
<div>I went through the Image Registration Section of the ITK software guide and I came to know that the appropriate metric for my problem is the </div>
<div>itk::<font color="#010001" size="2"><font color="#010001" size="2">MatchCardinalityImageToImageMetric. </font></font><font color="#010001" size="2"><font color="#010001" size="2">I also went through the corresponding example in itk --- "Examples\Registration\ImageRegistration10.cxx". </font></font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">I found that the MatchCardinalityImageToImageMetric does not provide analytical derivatives and simply counts the number of matches/mismatches. Hence the regular optimizers wouldnt work, and hence i tried to use the AmoebaOptimizer as shown in the example.</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">However i want to perform registration in the following order: <font color="#010001" size="2"><font color="#010001" size="2">Similarity Transform</font></font>, Affine, Deformable</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">To start with, i am just trying it with the Similarity3DTransform. </font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">itk::Similarity3DTransform derives from the itk::VersorRigid3DTransform and i read in the ITK software guide that the most appropriate optimizer for this transform is itk::VersorTransformOptimizer as it computes the versor derivatives as defined by hamilton. </font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">QUESTION:</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">Now Im confused as to which optimizer to use for my problem </font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">1. AmoebaOptimizer ( that is appropriate for MatchCardinalityImageToImageMetric)</font></div>
<div><font color="#010001">2. VersorTransformOptimizer (that is appropriate for Similarity3DTransform)</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">Also, does the VersorTransformOptimizer require analytical derivates of the metric (which the MatchCardinalityImageToImageMetric does not provide).</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">MY EXPERIMENTS:</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">I tried to use the AmoebaOptimizer with the MatchCardinalityImageToImageMetric and Similarity3DTransform. </font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">I was not clear how to assign the Initial Simplex for my transform parameters particularly those of the quaternion. So i let the optimizer determine it automatically.</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">However, the registration method fails with an exception. Below is the command line output:</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">****************************************************************************************</font></div>
<div><font color="#010001"></font> </div>
<div>Iter 1 : 0.1122 --- [0, 0, 0, 0, 0, 0, 1]
<div>Iter 2 : 0.117374 --- [0.00025, 0, 0, 0, 0, 0, 1]</div>
<div>Iter 3 : 0.114343 --- [0, 0.00025, 0, 0, 0, 0, 1]</div>
<div>Iter 4 : 0.114466 --- [0, 0, 0.00025, 0, 0, 0, 1]</div>
<div>Iter 5 : 0.113333 --- [0, 0, 0, 0.00025, 0, 0, 1]</div>
<div>Iter 6 : 0.113333 --- [0, 0, 0, 0, 0.00025, 0, 1]</div>
<div>Iter 7 : 0.1122 --- [0, 0, 0, 0, 0, 0.00025, 1]</div></div>
<div>ERROR-REGISTRATION :
<div>itk::ExceptionObject (013FFA90)</div>
<div>Location: "double __thiscall itk::MatchCardinalityImageToImageMetric<class itk::Image<unsigned char,3>,class itk::Image<unsigned char,3> >::GetNonconstValue(const class itk::Array<double> &)"</div>
<div>File: c:\itk\insighttoolkit-3.10.2\code\algorithms\itkMatchCardinalityImageToImageMetric.txx</div>
<div>Line: 130</div>
<div>Description: itk::ERROR: MatchCardinalityImageToImageMetric(018DCEE0): All the points mapped to outside of the moving image</div>
<div> </div></div>
<div>
<div>***************************************************************************************************</div></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">At the end of this message is a section of the code that i wrote ... </font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">Any help would be greatly appreciated.</font></div>
<div><font color="#010001"></font> </div>
<div><font color="#010001">Thanks in advance.</font></div>
<div><font color="#010001"></font> </div>
<div>Regards,</div>
<div> </div>
<div>Deepak</div>
<div> </div>
<div> </div>
<div>****************************** CODE ******************************</div>
<div> </div>
<div>// Perform registration with Similarity3DTransform first
<div>typedef itk::ImageRegistrationMethod<FixedImageType, MovingImageType> RegistrationType;</div>
<div>RegistrationType::Pointer pRegistrationMethod = RegistrationType::New(); </div></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> // Metric</div>
<div> typedef itk::MatchCardinalityImageToImageMetric<FixedImageType,MovingImageType> MetricType;</div>
<div> MetricType::Pointer pMetric = MetricType::New();</div>
<div> pMetric->MeasureMatchesOff();</div>
<div> pRegistrationMethod->SetMetric( pMetric );</div>
<div> </div>
<div> // Interpolator
<div> typedef itk::NearestNeighborInterpolateImageFunction< MovingImageType, double> InterpolatorType;</div>
<div> InterpolatorType::Pointer pInterpolator = InterpolatorType::New();</div></div>
<div> pRegistrationMethod->SetInterpolator( pInterpolator );</div>
<div> </div>
<div> // transform
<div> typedef itk::Similarity3DTransform<double> SimilarityTransformType;</div>
<div> typedef itk::CenteredTransformInitializer<SimilarityTransformType,FixedImageType,MovingImageType> TransformInitializerType;</div></div>
<div> </div>
<div> SimilarityTransformType::Pointer pTransform = SimilarityTransformType::New();
<div> TransformInitializerType::Pointer pTransformInitializer = TransformInitializerType::New();</div></div>
<div> </div>
<div> pTransformInitializer->SetFixedImage( pFixedImage );
<div> pTransformInitializer->SetMovingImage( pMovingImage );</div>
<div> pTransformInitializer->SetTransform( pTransform );</div>
<div> pTransformInitializer->MomentsOn();</div>
<div> pTransformInitializer->InitializeTransform(); </div></div>
<div> </div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> // rotation</div>
<div> typedef SimilarityTransformType::VersorType VersorType;</div>
<div> typedef VersorType::VectorType VectorType;</div>
<div> VectorType rot_axis;</div>
<div> rot_axis[0] = 0.0;
<div> rot_axis[1] = 0.0;</div>
<div> rot_axis[2] = 1.0;</div></div>
<div> pTransform->SetRotation( rot_axis , 0.0 );</div>
<div> </div>
<div> // scaling
<div> pTransform->SetScale( 1.0 );</div></div>
<div> pRegistrationMethod->SetInitialTransformParameters( pTransform->GetParameters() );
<div> pRegistrationMethod->SetTransform( pTransform ); </div></div></blockquote>
<div> // Optimizer
<div> typedef itk::AmoebaOptimizer OptimizerType;</div>
<div> OptimizerType::Pointer pOptimizer = OptimizerType::New();</div>
<div> OptimizerType::ParametersType simplexDelta( pTransform->GetNumberOfParameters() );</div></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div>// simplexDelta.Fill( 5.0 );</div>
<div>// pOptimizer->AutomaticInitialSimplexOff();</div>
<div>// pOptimizer->SetInitialSimplexDelta( simplexDelta );</div></blockquote>
<div> pOptimizer->SetParametersConvergenceTolerance( 0.25 ); // quarter pixel
<div> pOptimizer->SetFunctionConvergenceTolerance( 0.001 ); // 0.1%</div>
<div> pOptimizer->SetMaximumNumberOfIterations( 10 );</div></div>
<div> pRegistrationMethod->SetOptimizer( pOptimizer );</div>
<div> </div>
<div> // Observer
<div> typedef CommandIterationUpdate ObserverType;</div>
<div> ObserverType::Pointer pObserver = ObserverType::New();</div></div>
<div> pOptimizer->AddObserver( itk::IterationEvent() , pObserver);</div></blockquote>
<div> </div>
<div>pRegistrationMethod->SetFixedImage( pFixedImage );
<div>pRegistrationMethod->SetMovingImage( pMovingImage );</div>
<div>pRegistrationMethod->SetFixedImageRegion( pFixedImage->GetLargestPossibleRegion() );</div>
<div> </div></div>
<div>try
<div>{</div>
<div> pRegistrationMethod->Initialize();</div>
<div> pRegistrationMethod->StartRegistration();</div>
<div>}</div>
<div>catch(itk::ExceptionObject & err)</div>
<div>{</div>
<div> std::cout << "\nERROR-REGISTRATION : " << err << std::endl;</div></div>
<div> return EXIT_FAILURE;
<div>}</div>
<div> </div></div>
<div>RegistrationType::ParametersType finalParameters;</div>
<div>finalParameters = pRegistrationMethod->GetLastTransformParameters();</div>
<div> </div>
<div>std::cout << "Final: " << pMetric->GetValue( finalParameters ) << " --- " << finalParameters << std::endl;</div>
<div> </div>
<div>// Resampling -- Transform the moving image using the obtained transform parameters
<div>typedef itk::ResampleImageFilter<MovingImageType,FixedImageType> ResampleFilterType;</div>
<div>ResampleFilterType::Pointer pResampleImageFilter = ResampleFilterType::New();</div></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> // transform</div>
<div> SimilarityTransformType::Pointer pFinalTransform = SimilarityTransformType::New();</div>
<div> pFinalTransform->SetParameters( pRegistrationMethod->GetLastTransformParameters() );</div></blockquote>
<div>pResampleImageFilter->SetTransform( pFinalTransform );</div>
<div>pResampleImageFilter->SetInput( pMovingImage );
<div>pResampleImageFilter->SetSize( pFixedImage->GetLargestPossibleRegion().GetSize() );</div>
<div>pResampleImageFilter->SetOutputOrigin( pFixedImage->GetOrigin() );</div>
<div>pResampleImageFilter->SetOutputSpacing( pFixedImage->GetSpacing() );</div>
<div>pResampleImageFilter->SetOutputDirection( pFixedImage->GetDirection() );</div>
<div>pResampleImageFilter->SetDefaultPixelValue( 0 );</div>
<div>pResampleImageFilter->SetInterpolator( pInterpolator );</div></div>
<div>pResampleImageFilter->Update();</div>
<div> </div>
<div>************************************************************************************************</div>