7 #include <itkMultiplyImageFilter.h> 8 #include <itkSubtractImageFilter.h> 13 template <
typename TInputImageType>
15 KissingSymmetricBMRegistrationMethod <TInputImageType>
18 itk::TimeProbe tmpTime;
21 this->GetBlockMatcher()->SetForceComputeBlocks(
true);
22 this->GetBlockMatcher()->SetReferenceImage(refImage);
23 this->GetBlockMatcher()->SetMovingImage(movingImage);
25 this->ChangeDefaultBackgroundValue(refImage, m_FloatingBackgroundValue);
26 this->GetBlockMatcher()->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
27 this->GetBlockMatcher()->Update();
31 if (this->GetVerboseProgression())
32 std::cout <<
"Matching performed in " << tmpTime.GetTotal() << std::endl;
34 this->GetAgregator()->SetInputRegions(this->GetBlockMatcher()->GetBlockRegions());
35 this->GetAgregator()->SetInputOrigins(this->GetBlockMatcher()->GetBlockPositions());
36 this->GetAgregator()->SetInputWeights(this->GetBlockMatcher()->GetBlockWeights());
37 this->GetAgregator()->SetInputTransforms(this->GetBlockMatcher()->GetBlockTransformPointers());
41 itk::TimeProbe tmpTimeReverse;
42 tmpTimeReverse.Start();
44 this->GetBlockMatcher()->SetReferenceImage(movingImage);
45 this->GetBlockMatcher()->SetMovingImage(refImage);
47 this->ChangeDefaultBackgroundValue(refImage, m_ReferenceBackgroundValue);
48 this->GetBlockMatcher()->Update();
50 tmpTimeReverse.Stop();
52 if (this->GetVerboseProgression())
53 std::cout <<
"Matching performed in " << tmpTimeReverse.GetTotal() << std::endl;
55 this->GetAgregator()->SetInputRegions(this->GetBlockMatcher()->GetBlockRegions());
56 this->GetAgregator()->SetInputOrigins(this->GetBlockMatcher()->GetBlockPositions());
57 this->GetAgregator()->SetInputWeights(this->GetBlockMatcher()->GetBlockWeights());
58 this->GetAgregator()->SetInputTransforms(this->GetBlockMatcher()->GetBlockTransformPointers());
62 if (this->GetAgregator()->GetOutputTransformType() == AgregatorType::SVF)
67 typedef typename SVFTransformType::VectorFieldType VelocityFieldType;
69 typedef itk::MultiplyImageFilter <VelocityFieldType,itk::Image <double,InputImageType::ImageDimension>,VelocityFieldType> MultiplyFilterType;
70 typedef itk::SubtractImageFilter <VelocityFieldType,VelocityFieldType,VelocityFieldType> SubtractFilterType;
75 typename SubtractFilterType::Pointer subFilter = SubtractFilterType::New();
76 subFilter->SetInput1(usualAddOnCast->GetParametersAsVectorField());
77 subFilter->SetInput2(reverseAddOnCast->GetParametersAsVectorField());
78 subFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
79 subFilter->InPlaceOn();
83 typename MultiplyFilterType::Pointer multiplyFilter = MultiplyFilterType::New();
84 multiplyFilter->SetInput(subFilter->GetOutput());
85 multiplyFilter->SetConstant(0.25);
86 multiplyFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
87 multiplyFilter->InPlaceOn();
89 multiplyFilter->Update();
91 typename VelocityFieldType::Pointer addonSVF = multiplyFilter->GetOutput();
92 addonSVF->DisconnectPipeline();
94 usualAddOnCast->SetParametersAsVectorField(addonSVF);
101 unsigned int NDimensions = InputImageType::ImageDimension;
102 vnl_matrix <double> usualAddOnMatrix(NDimensions+1,NDimensions+1,0);
103 vnl_matrix <double> reverseAddOnMatrix(NDimensions+1,NDimensions+1,0);
104 usualAddOnMatrix.set_identity();
105 reverseAddOnMatrix.set_identity();
107 for (
unsigned int i = 0;i < NDimensions;++i)
109 for (
unsigned int j = 0;j < NDimensions;++j)
111 usualAddOnMatrix(i,j) = usualAddOnCast->GetMatrix()(i,j);
112 reverseAddOnMatrix(i,j) = reverseAddOnCast->GetMatrix()(i,j);
115 usualAddOnMatrix(i,NDimensions) = usualAddOnCast->GetOffset()[i];
116 reverseAddOnMatrix(i,NDimensions) = reverseAddOnCast->GetOffset()[i];
122 usualAddOnMatrix -= reverseAddOnMatrix;
123 usualAddOnMatrix /= 4.0;
127 typename AffineTransformType::MatrixType trsfMatrix;
129 for (
unsigned int i = 0;i < NDimensions;++i)
130 for (
unsigned int j = 0;j < NDimensions;++j)
131 trsfMatrix(i,j) = usualAddOnMatrix(i,j);
133 usualAddOnCast->SetMatrix(trsfMatrix);
135 typename AffineTransformType::OffsetType trsfOffset;
136 for (
unsigned int i = 0;i < NDimensions;++i)
137 trsfOffset[i] = usualAddOnMatrix(i,NDimensions);
139 usualAddOnCast->SetOffset(trsfOffset);
TInputImageType InputImageType
itk::AffineTransform< typename AgregatorType::ScalarType, TInputImageType::ImageDimension > AffineTransformType
vnl_matrix< T > GetExponential(const vnl_matrix< T > &m, const int numApprox=1)
Computation of the matrix exponential. Algo: classical scaling and squaring, as in Matlab...
vnl_matrix< T > GetLogarithm(const vnl_matrix< T > &m, const double precision=0.00000000001, const int numApprox=1)
Computation of the matrix logarithm. Algo: inverse scaling and squaring, variant proposed by Cheng et...
itk::StationaryVelocityFieldTransform< AgregatorScalarType, TInputImageType::ImageDimension > SVFTransformType
TransformType::Pointer TransformPointer