4 #include <itkImageRegionConstIteratorWithIndex.h> 14 template <
class TFixedImagePixelType,
class TMovingImagePixelType,
unsigned int ImageDimension >
18 m_FixedImagePoints.clear();
19 m_FixedImageValues.clear();
22 m_FixedDenominator = 0;
30 template <
class TFixedImagePixelType,
class TMovingImagePixelType,
unsigned int ImageDimension >
39 itkExceptionMacro( <<
"Fixed image has not been assigned" );
42 if ((this->m_NumberOfPixelsCounted <= 1)||(m_FixedDenominator == 0))
45 this->SetTransformParameters(parameters);
47 unsigned int vectorSize = m_FixedImageValues[0].GetSize();
53 unsigned int tensorDimension = floor((std::sqrt((
double)(8 * vectorSize + 1)) - 1) / 2.0);
55 vnl_matrix <double> tmpMat(tensorDimension, tensorDimension);
56 vnl_matrix <double> ppdOrientationMatrix(tensorDimension, tensorDimension);
57 typedef itk::Matrix <double, 3, 3> EigVecMatrixType;
58 typedef vnl_vector_fixed <double,3> EigValVectorType;
59 itk::SymmetricEigenAnalysis < EigVecMatrixType, EigValVectorType, EigVecMatrixType> eigenComputer(3);
60 EigVecMatrixType eigVecs;
61 EigValVectorType eigVals;
63 vnl_matrix <double> currentTensor(tensorDimension, tensorDimension);
64 double mST = 0, mRS = 0, mSS = 0;
66 double movingDenominator = 0;
67 double measureNumerator = 0;
68 unsigned int numOutside = 0;
70 for (
unsigned int i = 0;i < this->m_NumberOfPixelsCounted;++i)
72 transformedPoint = this->m_Transform->TransformPoint(m_FixedImagePoints[i]);
73 this->m_Interpolator->GetInputImage()->TransformPhysicalPointToContinuousIndex(transformedPoint,transformedIndex);
75 if( this->m_Interpolator->IsInsideBuffer(transformedIndex))
77 movingValue = this->m_Interpolator->EvaluateAtContinuousIndex(transformedIndex);
79 if (this->GetModelRotation() != Superclass::NONE)
84 if (this->GetModelRotation() == Superclass::FINITE_STRAIN)
88 eigenComputer.ComputeEigenValuesAndVectors(tmpMat,eigVals,eigVecs);
96 unsigned int pos_internal = 0;
97 for (
unsigned int j = 0;j < tensorDimension;++j)
98 for (
unsigned int k = 0;k <= j;++k)
101 mST += movingValue[pos_internal] * m_LogEpsilon;
103 mRS += m_FixedImageValues[i][pos_internal] * movingValue[pos_internal];
104 mSS += movingValue[pos_internal] * movingValue[pos_internal];
113 if (this->m_NumberOfPixelsCounted / 2.0 < numOutside)
116 movingDenominator = mSS + mST * mST * (3.0 * this->m_NumberOfPixelsCounted * m_LogEpsilon * m_LogEpsilon - 2.0);
118 if (movingDenominator == 0)
121 measureNumerator = mRS - mST * m_FixedTProduct;
123 double measure = measureNumerator * measureNumerator / (m_FixedDenominator * movingDenominator);
127 else if (measure < 0)
133 template <
class TFixedImagePixelType,
class TMovingImagePixelType,
unsigned int ImageDimension>
142 itkExceptionMacro( <<
"Fixed image has not been assigned" );
145 unsigned int vectorSize = fixedImage->GetNumberOfComponentsPerPixel();
146 unsigned int tensorDimension = floor((sqrt((
double)(8 * vectorSize + 1)) - 1) / 2.0);
148 this->m_NumberOfPixelsCounted = this->GetFixedImageRegion().GetNumberOfPixels();
150 m_FixedDenominator = 0;
154 m_LogEpsilon = 1.0 / std::sqrt(3.0 * this->m_NumberOfPixelsCounted);
156 typedef itk::ImageRegionConstIteratorWithIndex<FixedImageType> FixedIteratorType;
158 FixedIteratorType ti(fixedImage, this->GetFixedImageRegion());
159 typename FixedImageType::IndexType index;
161 m_FixedImagePoints.resize(this->m_NumberOfPixelsCounted);
162 m_FixedImageValues.resize(this->m_NumberOfPixelsCounted);
166 unsigned int pos = 0;
170 index = ti.GetIndex();
171 fixedImage->TransformIndexToPhysicalPoint(index, inputPoint);
173 m_FixedImagePoints[pos] = inputPoint;
174 fixedValue = ti.Get();
175 m_FixedImageValues[pos] = fixedValue;
177 unsigned int pos_internal = 0;
178 for (
unsigned int i = 0;i < tensorDimension;++i)
179 for (
unsigned int j = 0;j <= i;++j)
182 m_FixedTProduct += fixedValue[pos_internal] * m_LogEpsilon;
184 m_FixedDenominator += fixedValue[pos_internal] * fixedValue[pos_internal];
193 m_FixedDenominator += m_FixedTProduct * m_FixedTProduct * (3.0 * this->m_NumberOfPixelsCounted * m_LogEpsilon * m_LogEpsilon - 2.0);
Superclass::InputPointType InputPointType
itk::ContinuousIndex< double, ImageDimension > ContinuousIndexType
Superclass::MeasureType MeasureType
Superclass::FixedImageConstPointer FixedImageConstPointer
TensorCorrelationImageToImageMetric()
void GetVectorRepresentation(const vnl_matrix< T1 > &tensor, itk::VariableLengthVector< T2 > &vector, unsigned int vecDim=0, bool scale=false)
void RotateSymmetricMatrix(T1 &tensor, T2 &rotationMatrix, T3 &rotated_tensor, unsigned int tensorDim)
Rotates a symmetric matrix by performing R^T D R where R is a rotation matrix and D the symmetric mat...
void GetTensorFromVectorRepresentation(const itk::VariableLengthVector< T1 > &vector, vnl_matrix< T2 > &tensor, unsigned int tensDim=0, bool scale=false)
TFixedImage::PixelType PixelType
Superclass::TransformParametersType TransformParametersType
void PreComputeFixedValues()
MeasureType GetValue(const TransformParametersType ¶meters) const ITK_OVERRIDE
Superclass::OutputPointType OutputPointType
void ExtractPPDRotationFromJacobianMatrix(vnl_matrix< RealType > &jacobianMatrix, vnl_matrix< RealType > &rotationMatrix, MatrixType &eigenVectors)