From 35c2fa30ca32a147048a20d8f812e91c63d9ff57 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Wed, 31 Aug 2011 11:56:30 +0200 Subject: [PATCH] Added option itkbspline to use itk::BSpline instead of multilabels BLUTs --- registration/clitkBLUTDIR.ggo | 2 +- registration/clitkBLUTDIRGenericFilter.cxx | 47 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/registration/clitkBLUTDIR.ggo b/registration/clitkBLUTDIR.ggo index 55ac19f..ed3efce 100644 --- a/registration/clitkBLUTDIR.ggo +++ b/registration/clitkBLUTDIR.ggo @@ -39,7 +39,7 @@ option "order" - "Spline Order FFD" int no multiple default=" option "control" - "Internal control points for each dimension" int no multiple option "spacing" - "Control point spacing for each dimension (mm)" double no multiple option "samplingFactor" - "LUT sampling factor" int no multiple - +option "itkbspline" - "Use ITK BSpline instead of multilabel BLUT for debug" flag off section "Interpolator" diff --git a/registration/clitkBLUTDIRGenericFilter.cxx b/registration/clitkBLUTDIRGenericFilter.cxx index 0822bd9..39c1d3d 100644 --- a/registration/clitkBLUTDIRGenericFilter.cxx +++ b/registration/clitkBLUTDIRGenericFilter.cxx @@ -584,6 +584,25 @@ namespace clitk transform->SetParameters( parameters ); if (m_ArgsInfo.initCoeff_given) initializer->SetInitialParameters(m_ArgsInfo.initCoeff_arg, parameters); + //------------------------------------------------------------------------- + // DEBUG: use an itk BSpline instead of multilabel BLUTs + //------------------------------------------------------------------------- + typedef itk::Transform< TCoordRep, 3, 3 > RegistrationTransformType; + RegistrationTransformType::Pointer regTransform(transform); + typedef itk::BSplineDeformableTransform SingleBSplineTransformType; + typename SingleBSplineTransformType::Pointer sTransform; + if(m_ArgsInfo.itkbspline_flag) { + if( transform->GetTransforms().size()>1) + itkExceptionMacro(<< "invalid --itkbspline option if there is more than 1 label") + sTransform = SingleBSplineTransformType::New(); + sTransform->SetBulkTransform( transform->GetTransforms()[0]->GetBulkTransform() ); + sTransform->SetGridSpacing( transform->GetTransforms()[0]->GetGridSpacing() ); + sTransform->SetGridOrigin( transform->GetTransforms()[0]->GetGridOrigin() ); + sTransform->SetGridRegion( transform->GetTransforms()[0]->GetGridRegion() ); + sTransform->SetParameters( transform->GetTransforms()[0]->GetParameters() ); + regTransform = sTransform; + transform = NULL; // free memory + } //======================================================= // Interpolator @@ -625,7 +644,7 @@ namespace clitk GenericOptimizerType::Pointer genericOptimizer = GenericOptimizerType::New(); genericOptimizer->SetArgsInfo(m_ArgsInfo); genericOptimizer->SetMaximize(genericMetric->GetMaximize()); - genericOptimizer->SetNumberOfParameters(transform->GetNumberOfParameters()); + genericOptimizer->SetNumberOfParameters(regTransform->GetNumberOfParameters()); typedef itk::SingleValuedNonLinearOptimizer OptimizerType; OptimizerType::Pointer optimizer = genericOptimizer->GetOptimizerPointer(); @@ -638,7 +657,7 @@ namespace clitk registration->SetMetric( metric ); registration->SetOptimizer( optimizer ); registration->SetInterpolator( interpolator ); - registration->SetTransform (transform); + registration->SetTransform (regTransform ); if(threadsGiven) { registration->SetNumberOfThreads(threads); if (m_Verbose) std::cout<< "Using " << threads << " threads." << std::endl; @@ -648,7 +667,7 @@ namespace clitk registration->SetFixedImageRegion( metricRegion ); registration->SetFixedImagePyramid( fixedImagePyramid ); registration->SetMovingImagePyramid( movingImagePyramid ); - registration->SetInitialTransformParameters( transform->GetParameters() ); + registration->SetInitialTransformParameters( regTransform->GetParameters() ); registration->SetNumberOfLevels( m_ArgsInfo.levels_arg ); if (m_Verbose) std::cout<<"Setting the number of resolution levels to "< DVFCommandType; typename DVFCommandType::Pointer observerdvf = DVFCommandType::New(); @@ -707,7 +730,7 @@ namespace clitk // Get the result //======================================================= OptimizerType::ParametersType finalParameters = registration->GetLastTransformParameters(); - transform->SetParameters( finalParameters ); + regTransform->SetParameters( finalParameters ); if (m_Verbose) { std::cout<<"Stop condition description: " @@ -755,8 +778,11 @@ namespace clitk #endif typename ConvertorType::Pointer filter= ConvertorType::New(); filter->SetNumberOfThreads(1); - transform->SetBulkTransform(NULL); - filter->SetTransform(transform); + if(m_ArgsInfo.itkbspline_flag) + sTransform->SetBulkTransform(NULL); + else + transform->SetBulkTransform(NULL); + filter->SetTransform(regTransform); filter->SetOutputParametersFromImage(fixedImage); filter->Update(); typename DisplacementFieldType::Pointer field = filter->GetOutput(); @@ -786,8 +812,13 @@ namespace clitk //======================================================= typedef itk::ResampleImageFilter< MovingImageType, FixedImageType > ResampleFilterType; typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); - if (rigidTransform) transform->SetBulkTransform(rigidTransform); - resampler->SetTransform( transform ); + if (rigidTransform) { + if(m_ArgsInfo.itkbspline_flag) + sTransform->SetBulkTransform(rigidTransform); + else + transform->SetBulkTransform(rigidTransform); + } + resampler->SetTransform( regTransform ); resampler->SetInput( movingImage); resampler->SetOutputParametersFromImage(fixedImage); resampler->Update(); -- 2.47.1