5 #include <itkTransformFileReader.h> 6 #include <itkTransformFileWriter.h> 7 #include <itkCenteredTransformInitializer.h> 8 #include <itkMinimumMaximumImageFilter.h> 23 template <
unsigned int ImageDimension>
26 m_InitialTransform =
nullptr;
27 m_DirectionTransform =
nullptr;
28 m_ReferenceImage =
nullptr;
29 m_FloatingImage =
nullptr;
31 m_OutputTransform =
nullptr;
32 m_outputTransformFile =
"";
33 m_outputNearestRigidTransformFile =
"";
34 m_outputNearestSimilarityTransformFile =
"";
36 m_OutputImage =
nullptr;
38 m_ReferenceMinimalValue = 0.0;
39 m_FloatingMinimalValue = 0.0;
47 m_AffineDirection = 1;
51 m_MaximumIterations = 10;
52 m_MinimalTransformError = 0.01;
53 m_OptimizerMaximumIterations = 100;
55 m_SearchAngleRadius = 5;
56 m_SearchScaleRadius = 0.1;
57 m_FinalRadius = 0.001;
59 m_TranslateUpperBound = 50;
60 m_AngleUpperBound = 180;
61 m_ScaleUpperBound = 3;
62 m_Agregator = MEstimation;
63 m_OutputTransformType = outRigid;
64 m_AgregThreshold = 0.5;
65 m_SeStoppingThreshold = 0.01;
66 m_NumberOfPyramidLevels = 3;
67 m_LastPyramidLevel = 0;
68 m_PercentageKept = 0.8;
69 m_TransformInitializationType = ClosestTransform;
71 this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
76 m_callback = itk::CStyleCommand::New();
77 m_callback->SetClientData ((
void *)
this);
78 m_callback->SetCallback (ManageProgress);
81 template <
unsigned int ImageDimension>
86 template <
unsigned int ImageDimension>
95 template <
unsigned int ImageDimension>
98 if (initialTransformFile !=
"")
100 itk::TransformFileReader::Pointer tmpTrRead = itk::TransformFileReader::New();
101 tmpTrRead->SetFileName (initialTransformFile);
107 itk::TransformFileReader::TransformListType trsfList = * (tmpTrRead->GetTransformList());
108 itk::TransformFileReader::TransformListType::iterator tr_it = trsfList.begin();
113 catch (itk::ExceptionObject &e)
115 std::cerr <<
"Unable to read initial transform... Exiting..." << std::endl;
120 template <
unsigned int ImageDimension>
123 if (directionTransformFile !=
"")
125 itk::TransformFileReader::Pointer tmpTrRead = itk::TransformFileReader::New();
126 tmpTrRead->SetFileName(directionTransformFile);
132 itk::TransformFileReader::TransformListType trsfList = *(tmpTrRead->GetTransformList());
133 itk::TransformFileReader::TransformListType::iterator tr_it = trsfList.begin();
138 catch (itk::ExceptionObject &e)
140 std::cerr <<
"Unable to read direction transform... Exiting..." << std::endl;
145 template <
unsigned int ImageDimension>
153 m_progressReporter =
new itk::ProgressReporter(
this, 0, GetNumberOfPyramidLevels()*this->m_MaximumIterations);
154 this->AddObserver(itk::ProgressEvent(), m_progressCallback);
156 this->InvokeEvent(itk::StartEvent());
159 using MinMaxFilterType = itk::MinimumMaximumImageFilter <InputImageType>;
160 typename MinMaxFilterType::Pointer minMaxFilter = MinMaxFilterType::New();
161 minMaxFilter->SetInput(m_ReferenceImage);
162 if (this->GetNumberOfWorkUnits() != 0)
163 minMaxFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
164 minMaxFilter->Update();
166 m_ReferenceMinimalValue = minMaxFilter->GetMinimum();
168 minMaxFilter = MinMaxFilterType::New();
169 minMaxFilter->SetInput(m_FloatingImage);
170 if (this->GetNumberOfWorkUnits() != 0)
171 minMaxFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
172 minMaxFilter->Update();
174 m_FloatingMinimalValue = minMaxFilter->GetMinimum();
177 if (m_ReferenceMinimalValue < 0.0)
178 m_ReferenceMinimalValue = -1024;
180 m_ReferenceMinimalValue = 0.0;
182 if (m_FloatingMinimalValue < 0.0)
183 m_FloatingMinimalValue = -1024;
185 m_FloatingMinimalValue = 0.0;
188 this->SetupPyramids();
193 for (
unsigned int i = 0;i < GetNumberOfPyramidLevels() && !m_Abort; ++i)
195 if (i + GetLastPyramidLevel() >= m_ReferencePyramid->GetNumberOfLevels())
198 typename InputImageType::Pointer refImage = m_ReferencePyramid->GetOutput(i);
199 refImage->DisconnectPipeline();
201 typename InputImageType::Pointer floImage = m_FloatingPyramid->GetOutput(i);
202 floImage->DisconnectPipeline();
204 typename MaskImageType::Pointer maskGenerationImage = ITK_NULLPTR;
205 if (m_BlockGenerationPyramid)
207 maskGenerationImage = m_BlockGenerationPyramid->GetOutput(i);
208 maskGenerationImage->DisconnectPipeline();
211 BlockMatcherType *mainMatcher =
new BlockMatcherType;
212 BlockMatcherType *reverseMatcher = 0;
214 mainMatcher->SetBlockSize(GetBlockSize());
215 mainMatcher->SetBlockSpacing(GetBlockSpacing());
216 mainMatcher->SetBlockVarianceThreshold(GetStDevThreshold() * GetStDevThreshold());
217 mainMatcher->SetBlockGenerationMask(maskGenerationImage);
218 mainMatcher->SetDefaultBackgroundValue(m_FloatingMinimalValue);
222 std::cout <<
"Processing pyramid level " << i << std::endl;
223 std::cout <<
"Image size: " << refImage->GetLargestPossibleRegion().GetSize() << std::endl;
227 switch (m_SymmetryType)
232 m_bmreg = BlockMatchRegistrationType::New();
239 typename BlockMatchRegistrationType::Pointer tmpReg = BlockMatchRegistrationType::New();
241 reverseMatcher =
new BlockMatcherType;
242 reverseMatcher->SetBlockPercentageKept(GetPercentageKept());
243 reverseMatcher->SetBlockSize(GetBlockSize());
244 reverseMatcher->SetBlockSpacing(GetBlockSpacing());
245 reverseMatcher->SetBlockVarianceThreshold(GetStDevThreshold() * GetStDevThreshold());
246 reverseMatcher->SetVerbose(m_Verbose);
247 reverseMatcher->SetBlockGenerationMask(maskGenerationImage);
248 reverseMatcher->SetDefaultBackgroundValue(m_ReferenceMinimalValue);
250 tmpReg->SetReverseBlockMatcher(reverseMatcher);
259 typename BlockMatchRegistrationType::Pointer tmpReg = BlockMatchRegistrationType::New();
260 tmpReg->SetReferenceBackgroundValue(m_ReferenceMinimalValue);
261 tmpReg->SetFloatingBackgroundValue(m_FloatingMinimalValue);
268 mainMatcher->SetVerbose(m_Verbose);
269 m_bmreg->SetBlockMatcher(mainMatcher);
271 if (m_progressCallback)
276 m_bmreg->AddObserver(itk::ProgressEvent(), m_callback);
279 if (this->GetNumberOfWorkUnits() != 0)
280 m_bmreg->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
282 m_bmreg->SetFixedImage(refImage);
283 m_bmreg->SetMovingImage(floImage);
288 typename ResampleFilterType::Pointer refResampler = ResampleFilterType::New();
289 refResampler->SetSize(floImage->GetLargestPossibleRegion().GetSize());
290 refResampler->SetOutputOrigin(floImage->GetOrigin());
291 refResampler->SetOutputSpacing(floImage->GetSpacing());
292 refResampler->SetOutputDirection(floImage->GetDirection());
293 refResampler->SetDefaultPixelValue(m_ReferenceMinimalValue);
294 refResampler->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
295 m_bmreg->SetReferenceImageResampler(refResampler);
297 typename ResampleFilterType::Pointer movingResampler = ResampleFilterType::New();
298 movingResampler->SetSize(refImage->GetLargestPossibleRegion().GetSize());
299 movingResampler->SetOutputOrigin(refImage->GetOrigin());
300 movingResampler->SetOutputSpacing(refImage->GetSpacing());
301 movingResampler->SetOutputDirection(refImage->GetDirection());
302 movingResampler->SetDefaultPixelValue(m_FloatingMinimalValue);
303 movingResampler->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
304 m_bmreg->SetMovingImageResampler(movingResampler);
306 BaseAgreg *agreg = NULL;
308 switch (GetAgregator())
317 case LeastTrimmedSquares:
320 Agreg *tmpAg =
new Agreg;
323 tmpAg->SeStoppingThreshold(GetSeStoppingThreshold());
332 Agreg *tmpAg =
new Agreg;
335 tmpAg->SeStoppingThreshold(GetSeStoppingThreshold());
342 switch (GetOutputTransformType())
345 agreg->SetOutputTransformType(BaseAgreg::TRANSLATION);
348 agreg->SetOutputTransformType(BaseAgreg::RIGID);
350 case outAnisotropic_Sim:
351 agreg->SetOutputTransformType(BaseAgreg::ANISOTROPIC_SIM);
352 if (m_DirectionTransform)
353 agreg->SetOrthogonalDirectionMatrix(m_DirectionTransform->GetMatrix());
357 agreg->SetOutputTransformType(BaseAgreg::AFFINE);
361 agreg->SetVerboseAgregation(m_Verbose);
362 m_bmreg->SetAgregator(agreg);
364 switch (GetTransform())
376 case Directional_Affine:
377 mainMatcher->SetBlockTransformType(BlockMatcherType::Superclass::Directional_Affine);
378 mainMatcher->SetAffineDirection(m_AffineDirection);
381 reverseMatcher->SetBlockTransformType(BlockMatcherType::Superclass::Directional_Affine);
382 reverseMatcher->SetAffineDirection(m_AffineDirection);
394 switch(GetOptimizer())
430 m_bmreg->SetMaximumIterations(GetMaximumIterations());
431 m_bmreg->SetMinimalTransformError(GetMinimalTransformError());
432 m_bmreg->SetInitialTransform(m_OutputTransform);
434 mainMatcher->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
435 mainMatcher->SetOptimizerMaximumIterations(GetOptimizerMaximumIterations());
437 double sr = GetSearchRadius();
438 mainMatcher->SetSearchRadius(sr);
440 double sar = GetSearchAngleRadius();
441 mainMatcher->SetSearchAngleRadius(sar);
443 double scr = GetSearchScaleRadius();
444 mainMatcher->SetSearchScaleRadius(scr);
446 double fr = GetFinalRadius();
447 mainMatcher->SetFinalRadius(fr);
449 double ss = GetStepSize();
450 mainMatcher->SetStepSize(ss);
452 double tub = GetTranslateUpperBound();
453 mainMatcher->SetTranslateMax(tub);
455 double aub = GetAngleUpperBound();
456 mainMatcher->SetAngleMax(aub);
458 double scub = GetScaleUpperBound();
459 mainMatcher->SetScaleMax(scub);
463 reverseMatcher->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
464 reverseMatcher->SetOptimizerMaximumIterations(GetOptimizerMaximumIterations());
466 reverseMatcher->SetSearchRadius(sr);
467 reverseMatcher->SetSearchAngleRadius(sar);
468 reverseMatcher->SetSearchScaleRadius(scr);
469 reverseMatcher->SetFinalRadius(fr);
470 reverseMatcher->SetStepSize(ss);
471 reverseMatcher->SetTranslateMax(tub);
472 reverseMatcher->SetAngleMax(aub);
473 reverseMatcher->SetScaleMax(scub);
476 m_bmreg->SetVerboseProgression(m_Verbose);
482 catch( itk::ExceptionObject & err )
484 std::cerr <<
"ExceptionObject caught in bmreg startregistration ! " << err << std::endl;
488 if ((GetOutputTransformType() == outAnisotropic_Sim)||(GetOutputTransformType() == outAffine))
489 m_EstimationBarycenter = agreg->GetEstimationBarycenter();
493 tmpTrsf->SetParameters(m_bmreg->GetOutput()->Get()->GetParameters());
497 delete reverseMatcher;
503 std::cout <<
"Process aborted" << std::endl;
505 this->InvokeEvent(itk::EndEvent());
506 this->RemoveAllObservers();
512 typename AffineTransformType::Pointer trsfCopy = AffineTransformType::New();
513 trsfCopy->SetMatrix(tmpTrsf->GetMatrix());
514 trsfCopy->SetOffset(tmpTrsf->GetOffset());
516 tmpTrsf->Compose(trsfCopy);
519 if (!m_InitialTransform.IsNull())
520 tmpTrsf->Compose(m_InitialTransform,
false);
523 typename ResampleFilterType::Pointer tmpResample = ResampleFilterType::New();
524 tmpResample->SetTransform(m_OutputTransform);
525 tmpResample->SetInput(m_FloatingImage);
527 tmpResample->SetSize(m_ReferenceImage->GetLargestPossibleRegion().GetSize());
528 tmpResample->SetOutputOrigin(m_ReferenceImage->GetOrigin());
529 tmpResample->SetOutputSpacing(m_ReferenceImage->GetSpacing());
530 tmpResample->SetOutputDirection(m_ReferenceImage->GetDirection());
531 tmpResample->SetDefaultPixelValue(m_FloatingMinimalValue);
532 tmpResample->Update();
534 m_OutputImage = tmpResample->GetOutput();
535 m_OutputImage->DisconnectPipeline();
538 template <
unsigned int ImageDimension>
541 if (m_progressReporter)
542 m_progressReporter->CompletedPixel();
545 template <
unsigned int ImageDimension>
549 itk::ProcessObject *processObject = (itk::ProcessObject *) caller;
551 if (source && processObject)
552 source->
EmitProgress(processObject->GetProgress() * 100);
555 template <
unsigned int ImageDimension>
558 std::cout <<
"Writing output image to: " << GetResultFile() << std::endl;
559 anima::writeImage <InputImageType> (GetResultFile(),m_OutputImage);
561 if (GetOutputTransformFile() !=
"")
563 std::cout <<
"Writing output transform to: " << GetOutputTransformFile() << std::endl;
564 itk::TransformFileWriter::Pointer writer = itk::TransformFileWriter::New();
565 writer->SetInput(m_OutputTransform);
566 writer->SetFileName(GetOutputTransformFile());
570 if ((m_outputNearestRigidTransformFile ==
"")&&(m_outputNearestSimilarityTransformFile ==
""))
575 typename AffineTransformType::MatrixType linearMatrix = tmpTrsf->GetMatrix();
576 typename AffineTransformType::OffsetType transformOffset = tmpTrsf->GetOffset();
577 vnl_svd<typename AffineTransformType::MatrixType::ValueType> UWVLinearMatrixSVD(linearMatrix.GetVnlMatrix().as_matrix());
578 vnl_matrix<typename AffineTransformType::MatrixType::ValueType> leftRot = UWVLinearMatrixSVD.U()*vnl_determinant(UWVLinearMatrixSVD.U());
579 vnl_matrix<typename AffineTransformType::MatrixType::ValueType> rightRot = UWVLinearMatrixSVD.V()*vnl_determinant(UWVLinearMatrixSVD.V());
580 vnl_diag_matrix<typename AffineTransformType::MatrixType::ValueType> scal = UWVLinearMatrixSVD.W();
584 for (
unsigned int i = 0;i < ImageDimension;++i)
586 isoScal += std::abs(scal(i, i)) / ImageDimension;
587 ybar[i] = transformOffset[i];
589 for (
unsigned int j = 0;j < ImageDimension;++j)
590 ybar[i] += linearMatrix(i, j) * m_EstimationBarycenter[j];
593 typename AffineTransformType::OffsetType rigidOffset;
594 typename AffineTransformType::MatrixType linearPartRigid;
595 typename AffineTransformType::OffsetType similarityOffset;
596 typename AffineTransformType::MatrixType linearPartSimilarity;
597 typename AffineTransformType::OffsetType UOffset;
598 linearPartRigid.Fill(0);
599 linearPartSimilarity.Fill(0);
601 for (
unsigned int i = 0;i < ImageDimension;++i)
603 rigidOffset[i] = ybar[i];
604 similarityOffset[i] = ybar[i];
606 for (
unsigned int j = 0;j < ImageDimension; ++j)
608 for (
unsigned int k = 0;k < ImageDimension;++k)
610 linearPartRigid(i, j) += leftRot(i, k) * rightRot(j, k);
611 linearPartSimilarity(i, j) += isoScal * leftRot(i, k) * rightRot(j, k);
614 rigidOffset[i] -= linearPartRigid(i, j) * m_EstimationBarycenter[j];
615 similarityOffset[i] -= linearPartSimilarity(i, j) * m_EstimationBarycenter[j];
619 if (m_outputNearestRigidTransformFile !=
"")
622 rigidTransform->SetMatrix(linearPartRigid);
623 rigidTransform->SetOffset(rigidOffset);
624 itk::TransformFileWriter::Pointer rigidWriter = itk::TransformFileWriter::New();
625 rigidWriter->SetInput(rigidTransform);
626 rigidWriter->SetFileName(GetOutputNearestRigidTransformFile());
627 std::cout <<
"Writing output nearest rigid transform to: " << GetOutputNearestRigidTransformFile() << std::endl;
628 rigidWriter->Update();
631 if (m_outputNearestSimilarityTransformFile !=
"")
634 similarityTransform->SetMatrix(linearPartSimilarity);
635 similarityTransform->SetOffset(similarityOffset);
636 itk::TransformFileWriter::Pointer similarityWriter = itk::TransformFileWriter::New();
637 similarityWriter->SetInput(similarityTransform);
638 similarityWriter->SetFileName(GetOutputNearestSimilarityTransformFile());
639 std::cout <<
"Writing output nearest similarity transform to: " << GetOutputNearestSimilarityTransformFile() << std::endl;
640 similarityWriter->Update();
644 template <
unsigned int ImageDimension>
651 m_ReferencePyramid = PyramidType::New();
653 m_ReferencePyramid->SetInput(m_ReferenceImage);
654 m_ReferencePyramid->SetNumberOfLevels(GetNumberOfPyramidLevels());
655 m_ReferencePyramid->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
657 typename ResampleFilterType::Pointer refResampler = ResampleFilterType::New();
658 refResampler->SetDefaultPixelValue(m_ReferenceMinimalValue);
659 m_ReferencePyramid->SetImageResampler(refResampler);
660 m_ReferencePyramid->Update();
662 InputImagePointer initialFloatingImage = const_cast <InputImageType *> (m_FloatingImage.GetPointer());
665 if (m_InitialTransform.IsNotNull())
667 typename ResampleFilterType::Pointer tmpResample = ResampleFilterType::New();
668 tmpResample->SetTransform(m_InitialTransform);
669 tmpResample->SetInput(m_FloatingImage);
671 tmpResample->SetSize(m_ReferenceImage->GetLargestPossibleRegion().GetSize());
672 tmpResample->SetOutputOrigin(m_ReferenceImage->GetOrigin());
673 tmpResample->SetOutputSpacing(m_ReferenceImage->GetSpacing());
674 tmpResample->SetOutputDirection(m_ReferenceImage->GetDirection());
675 tmpResample->SetDefaultPixelValue(m_FloatingMinimalValue);
676 tmpResample->Update();
678 initialFloatingImage = tmpResample->GetOutput();
679 initialFloatingImage->DisconnectPipeline();
683 m_InitialTransform = NULL;
685 m_InitialTransform = AffineTransformType::New();
686 m_InitialTransform->SetIdentity();
688 typedef itk::ImageMomentsCalculator <InputImageType> ImageCalculatorType;
690 if (m_TransformInitializationType != Identity)
692 typename ImageCalculatorType::Pointer fixedCalculator = ImageCalculatorType::New();
693 fixedCalculator->SetImage(m_ReferenceImage);
694 fixedCalculator->Compute();
695 typename ImageCalculatorType::VectorType fixedBar = fixedCalculator->GetCenterOfGravity();
697 typename ImageCalculatorType::Pointer movingCalculator = ImageCalculatorType::New();
698 movingCalculator->SetImage(m_FloatingImage);
699 movingCalculator->Compute();
700 typename ImageCalculatorType::VectorType movingBar = movingCalculator->GetCenterOfGravity();
702 m_InitialTransform->SetOffset(movingBar - fixedBar);
704 if ((m_TransformInitializationType == ClosestTransform)&&(m_OutputTransformType != outTranslation))
706 typename ImageCalculatorType::VectorType fixedPrincipalMom = fixedCalculator->GetPrincipalMoments();
707 typename ImageCalculatorType::ScalarType fixedMass = fixedCalculator->GetTotalMass();
709 typename ImageCalculatorType::VectorType movingPrincipalMom = movingCalculator->GetPrincipalMoments();
710 typename ImageCalculatorType::ScalarType movingMass = movingCalculator->GetTotalMass();
712 vnl_matrix<double> scalMatrix(ImageDimension, ImageDimension, 0);
713 itk::Vector<double, ImageDimension> scalOffset;
714 double fixedScalFactor = 0;
715 double movingScalFactor = 0;
717 for (
unsigned int i = 0; i < ImageDimension; ++i)
719 fixedScalFactor += pow(fixedPrincipalMom[i] / fixedMass, 0.5);
720 movingScalFactor += pow(movingPrincipalMom[i] / movingMass, 0.5);
723 double scalingFactor = 1.0;
724 if ((m_OutputTransformType == outAnisotropic_Sim)||(m_OutputTransformType == outAffine))
725 scalingFactor = movingScalFactor / fixedScalFactor;
727 scalMatrix.fill_diagonal(scalingFactor);
729 for (
unsigned int i = 0; i < ImageDimension; ++i)
730 scalOffset[i] = movingBar[i] - scalingFactor * fixedBar[i];
732 m_InitialTransform->SetMatrix(scalMatrix);
733 m_InitialTransform->SetOffset(scalOffset);
737 typename ResampleFilterType::Pointer tmpResample = ResampleFilterType::New();
738 tmpResample->SetTransform(m_InitialTransform);
739 tmpResample->SetInput(m_FloatingImage);
741 tmpResample->SetSize(m_ReferenceImage->GetLargestPossibleRegion().GetSize());
742 tmpResample->SetOutputOrigin(m_ReferenceImage->GetOrigin());
743 tmpResample->SetOutputSpacing(m_ReferenceImage->GetSpacing());
744 tmpResample->SetOutputDirection(m_ReferenceImage->GetDirection());
745 tmpResample->SetDefaultPixelValue(m_FloatingMinimalValue);
746 tmpResample->Update();
748 initialFloatingImage = tmpResample->GetOutput();
749 initialFloatingImage->DisconnectPipeline();
751 using MinMaxImageFilterType = itk::MinimumMaximumImageFilter <InputImageType>;
752 typename MinMaxImageFilterType::Pointer minMaxFilter = MinMaxImageFilterType::New();
753 minMaxFilter->SetInput(initialFloatingImage);
754 minMaxFilter->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
755 minMaxFilter->Update();
757 if ((minMaxFilter->GetMinimum() == minMaxFilter->GetMaximum())&&(m_TransformInitializationType == Identity))
759 std::cout <<
"Identity initialization outputs an empty image, initializing with centers of mass" << std::endl;
760 m_TransformInitializationType = GravityCenters;
762 typename ImageCalculatorType::Pointer fixedCalculator = ImageCalculatorType::New();
763 fixedCalculator->SetImage(m_ReferenceImage);
764 fixedCalculator->Compute();
765 typename ImageCalculatorType::VectorType fixedBar = fixedCalculator->GetCenterOfGravity();
767 typename ImageCalculatorType::Pointer movingCalculator = ImageCalculatorType::New();
768 movingCalculator->SetImage(m_FloatingImage);
769 movingCalculator->Compute();
770 typename ImageCalculatorType::VectorType movingBar = movingCalculator->GetCenterOfGravity();
772 m_InitialTransform->SetOffset(movingBar - fixedBar);
774 typename ResampleFilterType::Pointer tmpResample = ResampleFilterType::New();
775 tmpResample->SetTransform(m_InitialTransform);
776 tmpResample->SetInput(m_FloatingImage);
778 tmpResample->SetSize(m_ReferenceImage->GetLargestPossibleRegion().GetSize());
779 tmpResample->SetOutputOrigin(m_ReferenceImage->GetOrigin());
780 tmpResample->SetOutputSpacing(m_ReferenceImage->GetSpacing());
781 tmpResample->SetOutputDirection(m_ReferenceImage->GetDirection());
782 tmpResample->SetDefaultPixelValue(m_FloatingMinimalValue);
783 tmpResample->Update();
785 initialFloatingImage = tmpResample->GetOutput();
786 initialFloatingImage->DisconnectPipeline();
791 m_FloatingPyramid = PyramidType::New();
793 m_FloatingPyramid->SetInput(initialFloatingImage);
794 m_FloatingPyramid->SetNumberOfLevels(GetNumberOfPyramidLevels());
795 m_FloatingPyramid->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
797 typename ResampleFilterType::Pointer floResampler = ResampleFilterType::New();
798 floResampler->SetDefaultPixelValue(m_FloatingMinimalValue);
799 m_FloatingPyramid->SetImageResampler(floResampler);
801 m_FloatingPyramid->Update();
803 m_BlockGenerationPyramid = 0;
804 if (m_BlockGenerationMask)
809 typename MaskResampleFilterType::Pointer maskResampler = MaskResampleFilterType::New();
811 m_BlockGenerationPyramid = MaskPyramidType::New();
812 m_BlockGenerationPyramid->SetImageResampler(maskResampler);
813 m_BlockGenerationPyramid->SetInput(m_BlockGenerationMask);
814 m_BlockGenerationPyramid->SetNumberOfLevels(GetNumberOfPyramidLevels());
815 m_BlockGenerationPyramid->SetNumberOfWorkUnits(GetNumberOfWorkUnits());
816 m_BlockGenerationPyramid->Update();
void SetDirectionTransform(AffineTransformPointer directionTransform)
InputImageType::PointType PointType
virtual ~PyramidalBlockMatchingBridge()
void Update() ITK_OVERRIDE
static void ManageProgress(itk::Object *caller, const itk::EventObject &event, void *clientData)
PyramidalBlockMatchingBridge()
void EmitProgress(int prog)
itk::AffineTransform< typename AgregatorType::ScalarType, ImageDimension > AffineTransformType
void SetBlockPercentageKept(double val)
AffineTransformType::Pointer AffineTransformPointer
InputImageType::Pointer InputImagePointer
itk::Image< unsigned char, ImageDimension > MaskImageType
itk::Image< double, ImageDimension > InputImageType
void SetInitialTransform(AffineTransformPointer initialTransform)