/usr/include/InsightToolkit/Algorithms/itkMeanSquareRegistrationFunction.txx is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkMeanSquareRegistrationFunction.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkMeanSquareRegistrationFunction_txx
#define __itkMeanSquareRegistrationFunction_txx
#include "itkMeanSquareRegistrationFunction.h"
#include "itkExceptionObject.h"
#include "vnl/vnl_math.h"
namespace itk {
/**
* Default constructor
*/
template <class TFixedImage, class TMovingImage, class TDeformationField>
MeanSquareRegistrationFunction<TFixedImage,TMovingImage,TDeformationField>
::MeanSquareRegistrationFunction()
{
RadiusType r;
unsigned int j;
for( j = 0; j < ImageDimension; j++ )
{
r[j] = 0;
}
this->SetRadius(r);
this->SetEnergy(0.0);
m_TimeStep = 1.0;
m_DenominatorThreshold = 1e-9;
m_IntensityDifferenceThreshold = 0.001;
this->SetMovingImage(NULL);
this->SetFixedImage(NULL);
m_FixedImageGradientCalculator = GradientCalculatorType::New();
typename DefaultInterpolatorType::Pointer interp =
DefaultInterpolatorType::New();
m_MovingImageInterpolator = static_cast<InterpolatorType*>(
interp.GetPointer() );
}
/*
* Standard "PrintSelf" method.
*/
template <class TFixedImage, class TMovingImage, class TDeformationField>
void
MeanSquareRegistrationFunction<TFixedImage,TMovingImage,TDeformationField>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
/*
os << indent << "MovingImageIterpolator: ";
os << m_MovingImageInterpolator.GetPointer() << std::endl;
os << indent << "FixedImageGradientCalculator: ";
os << m_FixedImageGradientCalculator.GetPointer() << std::endl;
os << indent << "DenominatorThreshold: ";
os << m_DenominatorThreshold << std::endl;
os << indent << "IntensityDifferenceThreshold: ";
os << m_IntensityDifferenceThreshold << std::endl;
*/
}
/*
* Set the function state values before each iteration
*/
template <class TFixedImage, class TMovingImage, class TDeformationField>
void
MeanSquareRegistrationFunction<TFixedImage,TMovingImage,TDeformationField>
::InitializeIteration()
{
if( !this->GetMovingImage() || !this->GetFixedImage() || !m_MovingImageInterpolator )
{
itkExceptionMacro( << "MovingImage, FixedImage and/or Interpolator not set" );
}
// cache fixed image information
m_FixedImageSpacing = this->GetFixedImage()->GetSpacing();
// setup gradient calculator
m_FixedImageGradientCalculator->SetInputImage( this->GetFixedImage() );
// setup moving image interpolator
m_MovingImageInterpolator->SetInputImage( this->GetMovingImage() );
this->SetEnergy(0.0);
}
/**
* Compute update at a non boundary neighbourhood
*/
template <class TFixedImage, class TMovingImage, class TDeformationField>
typename MeanSquareRegistrationFunction<TFixedImage,TMovingImage,TDeformationField>
::PixelType
MeanSquareRegistrationFunction<TFixedImage,TMovingImage,TDeformationField>
::ComputeUpdate(const NeighborhoodType &it, void * itkNotUsed(globalData),
const FloatOffsetType& itkNotUsed(offset))
{
// Get fixed image related information
// Note: no need to check the index is within
// fixed image buffer. This is done by the external filter.
const IndexType index = it.GetIndex();
const double fixedValue = (double) this->GetFixedImage()->GetPixel( index );
const CovariantVectorType fixedGradient = m_FixedImageGradientCalculator->EvaluateAtIndex( index );
double fixedGradientSquaredMagnitude = 0;
for(unsigned int j = 0; j < ImageDimension; j++ )
{
fixedGradientSquaredMagnitude += vnl_math_sqr( fixedGradient[j] ) * m_FixedImageSpacing[j];
}
// Get moving image related information
const DeformationFieldPixelType itvec = this->GetDeformationField()->GetPixel(index);
PointType mappedPoint;
this->GetFixedImage()->TransformIndexToPhysicalPoint(index, mappedPoint);
for(unsigned int j = 0; j < ImageDimension; j++ )
{
mappedPoint[j] += itvec[j];
}
double movingValue=0.0;
if( m_MovingImageInterpolator->IsInsideBuffer( mappedPoint ) )
{
movingValue = m_MovingImageInterpolator->Evaluate( mappedPoint );
}
// Compute update
const double speedValue = fixedValue - movingValue;
this->m_Energy += speedValue * speedValue;
const bool normalizemetric=this->GetNormalizeGradient();
double denominator = 1.0;
if (normalizemetric)
{
denominator = speedValue*speedValue *fixedGradientSquaredMagnitude;
denominator = vcl_sqrt(denominator);
}
if (denominator == 0)
{
denominator=1.0;
}
PixelType update;
if ( vnl_math_abs(speedValue) < m_IntensityDifferenceThreshold ||
denominator < m_DenominatorThreshold )
{
update.Fill(0.0);
return update;
}
for(unsigned int j = 0; j < ImageDimension; j++ )
{
update[j] = speedValue * fixedGradient[j] * vnl_math_sqr(m_FixedImageSpacing[j]) /
denominator*this->m_GradientStep;
}
return update;
}
} // end namespace itk
#endif
|