9 #include <itkImageRegionIterator.h> 14 template <
typename TInputImageType>
15 BaseBMRegistrationMethod <TInputImageType>
22 m_SVFElasticRegSigma = 0;
23 m_BCHCompositionOrder = 1;
24 m_ExponentiationOrder = 0;
26 m_MaximumIterations = 10;
27 m_MinimalTransformError = 0.0001;
29 m_ReferenceImageResampler = 0;
30 m_MovingImageResampler = 0;
32 m_VerboseProgression =
true;
34 this->SetNumberOfWorkUnits(this->GetMultiThreader()->GetNumberOfWorkUnits());
36 m_InitialTransform = 0;
37 this->SetNumberOfRequiredOutputs(1);
39 this->itk::ProcessObject::SetNthOutput(0, transformDecorator.GetPointer());
45 template <
typename TInputImageType>
53 template <
typename TInputImageType>
54 itk::DataObject::Pointer
61 return static_cast <itk::DataObject*> (TransformOutputType::New().GetPointer());
64 itkExceptionMacro(
"MakeOutput request for an output number larger than the expected number of outputs");
72 template <
typename TInputImageType>
78 this->StartOptimization();
84 template <
typename TInputImageType>
89 m_Agregator->SetInputTransformType(m_BlockMatcher->GetAgregatorInputTransformType());
92 this->SetupTransform(computedTransform);
95 itk::ProgressReporter progress(
this, 0, m_MaximumIterations);
99 for (
unsigned int iterations = 0; iterations < m_MaximumIterations && !m_Abort; ++iterations)
102 this->ResampleImages(computedTransform, fixedResampled, movingResampled);
106 this->GetAgregator()->SetCurrentLinearTransform(computedTransform);
108 this->PerformOneIteration(fixedResampled, movingResampled, addOn);
110 bool continueLoop = this->ComposeAddOnWithTransform(computedTransform,addOn);
112 if (m_VerboseProgression)
113 std::cout <<
"Iteration " << iterations <<
" done..." << std::endl;
115 if (iterations != m_MaximumIterations - 1)
116 progress.CompletedPixel();
123 transformDecorator->Set(computedTransform.GetPointer());
125 this->itk::ProcessObject::SetNthOutput(0, transformDecorator.GetPointer());
128 template <
typename TInputImageType>
133 if (m_Agregator->GetOutputTransformType() != AgregatorType::SVF)
135 if (m_InitialTransform)
137 optimizedTransform = AffineTransformType::New();
138 optimizedTransform->SetParameters(m_InitialTransform->GetParameters());
142 typename AffineTransformType::Pointer tmpTrsf = AffineTransformType::New();
143 tmpTrsf->SetIdentity();
144 optimizedTransform = tmpTrsf;
149 if (m_InitialTransform)
150 optimizedTransform = m_InitialTransform;
154 tmpTrsf->SetIdentity();
155 optimizedTransform = tmpTrsf;
160 template <
typename TInputImageType>
166 if (m_MovingImage->GetNumberOfComponentsPerPixel() > 1)
170 InternalFilterType *resampleFilter = dynamic_cast <InternalFilterType *> (m_MovingImageResampler.GetPointer());
172 if (m_Agregator->GetOutputTransformType() == AgregatorType::SVF)
180 resampleFilter->SetTransform(dispTrsf);
183 resampleFilter->SetTransform(currentTransform);
188 typedef itk::Image <ImageScalarType, TInputImageType::ImageDimension> InternalScalarImageType;
190 InternalFilterType *resampleFilter = dynamic_cast <InternalFilterType *> (m_MovingImageResampler.GetPointer());
192 if (m_Agregator->GetOutputTransformType() == AgregatorType::SVF)
200 resampleFilter->SetTransform(dispTrsf);
203 resampleFilter->SetTransform(currentTransform);
206 m_MovingImageResampler->SetInput(m_MovingImage);
207 m_MovingImageResampler->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
208 m_MovingImageResampler->Update();
210 movingImage = m_MovingImageResampler->GetOutput();
211 movingImage->DisconnectPipeline();
214 if (m_FixedImage->GetNumberOfComponentsPerPixel() > 1)
218 InternalFilterType *resampleFilter = dynamic_cast <InternalFilterType *> (m_ReferenceImageResampler.GetPointer());
220 if (m_Agregator->GetOutputTransformType() == AgregatorType::SVF)
228 resampleFilter->SetTransform(dispTrsf);
234 resampleFilter->SetTransform(reverseTrsf);
240 typedef itk::Image <ImageScalarType, TInputImageType::ImageDimension> InternalScalarImageType;
242 InternalFilterType *resampleFilter = dynamic_cast <InternalFilterType *> (m_ReferenceImageResampler.GetPointer());
244 if (m_Agregator->GetOutputTransformType() == AgregatorType::SVF)
252 resampleFilter->SetTransform(dispTrsf);
258 resampleFilter->SetTransform(reverseTrsf);
262 m_ReferenceImageResampler->SetInput(m_FixedImage);
263 m_ReferenceImageResampler->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
264 m_ReferenceImageResampler->Update();
266 refImage = m_ReferenceImageResampler->GetOutput();
267 refImage->DisconnectPipeline();
270 template <
typename TInputImageType>
275 if (m_Agregator->GetOutputTransformType() != AgregatorType::SVF)
277 typename TransformType::ParametersType oldPars = computedTransform->GetParameters();
279 if (m_Agregator->GetOutputTransformType() != AgregatorType::ANISOTROPIC_SIM)
283 tmpTrsf->Compose(tmpAddOn,
true);
288 computedTransform->SetParameters(addOn->GetParameters());
291 typename TransformType::ParametersType newPars = computedTransform->GetParameters();
295 for (
unsigned int i = 0; i < newPars.Size(); ++i)
296 err += std::pow(newPars[i] - oldPars[i], 2.);
298 if (err <= m_MinimalTransformError)
307 anima::composeSVF(tmpTrsf,tmpAddOn,this->GetNumberOfWorkUnits(),m_BCHCompositionOrder);
309 typedef typename SVFTransformType::VectorFieldType VectorFieldType;
310 typedef itk::ImageRegionConstIterator <VectorFieldType> IteratorType;
311 IteratorType diffItr(tmpAddOn->GetParametersAsVectorField(),
312 tmpAddOn->GetParametersAsVectorField()->GetLargestPossibleRegion());
314 bool smallEnoughTransform =
true;
315 while (!diffItr.IsAtEnd())
318 for (
unsigned int i = 0;i < VectorFieldType::ImageDimension;++i)
319 err += diffItr.Get()[i] * diffItr.Get()[i];
321 if (err > m_MinimalTransformError)
323 smallEnoughTransform =
false;
330 if (smallEnoughTransform)
333 if (m_SVFElasticRegSigma > 0)
335 typedef typename SVFTransformType::VectorFieldType VelocityFieldType;
338 typename SmoothingFilterType::Pointer smootherPtr = SmoothingFilterType::New();
340 smootherPtr->SetInput(tmpTrsf->GetParametersAsVectorField());
341 smootherPtr->SetSigma(m_SVFElasticRegSigma);
342 smootherPtr->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
344 smootherPtr->Update();
346 typename VelocityFieldType::Pointer tmpSmoothed = smootherPtr->GetOutput();
347 tmpSmoothed->DisconnectPipeline();
349 tmpTrsf->SetParametersAsVectorField(tmpSmoothed);
359 template <
typename TInputImageType>
362 ::PrintSelf(std::ostream& os, itk::Indent indent)
const 364 Superclass::PrintSelf( os, indent );
366 os << indent <<
"Fixed Image: " << m_FixedImage.GetPointer() << std::endl;
367 os << indent <<
"Moving Image: " << m_MovingImage.GetPointer() << std::endl;
369 os << indent <<
"Maximum Iterations: " << m_MaximumIterations << std::endl;
TransformOutputType::Pointer TransformOutputPointer
SVFTransformType::Pointer SVFTransformPointer
DisplacementFieldTransformType::Pointer DisplacementFieldTransformPointer
AgregatorType::BaseOutputTransformType TransformType
itk::AffineTransform< typename AgregatorType::ScalarType, TInputImageType::ImageDimension > AffineTransformType
InputImageType::Pointer InputImagePointer
itk::DataObjectDecorator< TransformType > TransformOutputType
void GetSVFExponential(itk::StationaryVelocityFieldTransform< ScalarType, NDimensions > *baseTrsf, rpi::DisplacementFieldTransform< ScalarType, NDimensions > *resultTransform, unsigned int exponentiationOrder, unsigned int numThreads, bool invert)
void composeSVF(itk::StationaryVelocityFieldTransform< ScalarType, NDimensions > *baseTrsf, itk::StationaryVelocityFieldTransform< ScalarType, NDimensions > *addonTrsf, unsigned int numThreads, unsigned int bchOrder)
itk::StationaryVelocityFieldTransform< AgregatorScalarType, TInputImageType::ImageDimension > SVFTransformType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
TransformType::Pointer TransformPointer