/usr/include/OTB-5.8/otbNCCRegistrationFunction.txx is in libotb-dev 5.8.0+dfsg-3.
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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.txt
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 otbNCCRegistrationFunction_txx
#define otbNCCRegistrationFunction_txx
#include "vnl/vnl_math.h"
#include "itkNeighborhoodIterator.h"
#include "otbMacro.h"
#include "otbNCCRegistrationFunction.h"
namespace otb
{
/*
* Default constructor
*/
template <class TFixedImage, class TMovingImage, class TDisplacementField>
NCCRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
::NCCRegistrationFunction()
{
RadiusType r;
unsigned int j;
for (j = 0; j < ImageDimension; ++j)
{
r[j] = 1;
}
this->SetRadius(r);
m_MetricTotal = 0.0;
m_TimeStep = 1.0;
m_DenominatorThreshold = 1e-9;
m_IntensityDifferenceThreshold = 0.001;
this->SetMovingImage(ITK_NULLPTR);
this->SetFixedImage(ITK_NULLPTR);
m_FixedImageSpacing.Fill(1.0);
m_FixedImageOrigin.Fill(0.0);
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 TDisplacementField>
void
NCCRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
::PrintSelf(std::ostream& os, itk::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 TDisplacementField>
void
NCCRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
::InitializeIteration()
{
if (!this->m_MovingImage || !this->m_FixedImage || !m_MovingImageInterpolator)
{
itkExceptionMacro(<< "MovingImage, FixedImage and/or Interpolator not set");
}
// cache fixed image information
m_FixedImageSpacing = this->m_FixedImage->GetSpacing();
m_FixedImageOrigin = this->m_FixedImage->GetOrigin();
// setup gradient calculator
m_FixedImageGradientCalculator->SetInputImage(this->m_FixedImage);
// setup moving image interpolator
m_MovingImageInterpolator->SetInputImage(this->m_MovingImage);
otbMsgDevMacro( " total metric " << m_MetricTotal << " field size " <<
this->GetDisplacementField()->GetLargestPossibleRegion().GetSize() << " image size " <<
this->m_FixedImage->GetLargestPossibleRegion().GetSize() );
m_MetricTotal = 0.0;
}
/*
* Compute update at a non boundary neighbourhood
*/
template <class TFixedImage, class TMovingImage, class TDisplacementField>
typename NCCRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
::PixelType
NCCRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>
::ComputeUpdate(const NeighborhoodType& it, void * itkNotUsed(globalData),
const FloatOffsetType& itkNotUsed(offset))
{
PixelType update;
update.Fill(0.0);
unsigned int j;
IndexType oindex = it.GetIndex();
typename FixedImageType::SizeType hradius = it.GetRadius();
FixedImageType* img = const_cast<FixedImageType *>(this->m_FixedImage.GetPointer());
typename FixedImageType::SizeType imagesize = img->GetLargestPossibleRegion().GetSize();
itk::NeighborhoodIterator<FixedImageType>
hoodIt(hradius, img, img->GetRequestedRegion());
hoodIt.SetLocation(oindex);
double sff = 0.0;
double smm = 0.0;
double sfm = 0.0;
double fixedValue;
double movingValue;
double derivativeF[ImageDimension];
double derivativeM[ImageDimension];
for (j = 0; j < ImageDimension; ++j)
{
derivativeF[j] = 0;
derivativeM[j] = 0;
}
unsigned int indct;
unsigned int hoodlen = hoodIt.Size();
for (indct = 0; indct < hoodlen - 1; indct++)
{
IndexType index = hoodIt.GetIndex(indct);
bool inimage = true;
for (unsigned int dd = 0; dd < ImageDimension; dd++)
{
if (index[dd] < 0 || index[dd] >
static_cast<typename IndexType::IndexValueType>(imagesize[dd] - 1)) inimage = false;
}
if (inimage)
{
// Get fixed image related information
CovariantVectorType fixedGradient;
double fixedGradientSquaredMagnitude = 0;
// Note: no need to check the index is within
// fixed image buffer. This is done by the external filter.
fixedValue = (double) this->m_FixedImage->GetPixel(index);
fixedGradient = m_FixedImageGradientCalculator->EvaluateAtIndex(index);
for (j = 0; j < ImageDimension; ++j)
{
fixedGradientSquaredMagnitude += vnl_math_sqr(fixedGradient[j]) * m_FixedImageSpacing[j];
}
// Get moving image related information
PointType mappedPoint;
typedef typename TDisplacementField::PixelType DisplacementPixelType;
// Edited by OTB developers
DisplacementPixelType vec;
vec.Fill(0);
if (this->GetDisplacementField()->GetBufferedRegion().IsInside(index))
{
vec = this->GetDisplacementField()->GetPixel(index);
}
// End Edited by OTB developers
for (j = 0; j < ImageDimension; ++j)
{
mappedPoint[j] = double(index[j]) * m_FixedImageSpacing[j] +
m_FixedImageOrigin[j];
mappedPoint[j] += vec[j];
}
if (m_MovingImageInterpolator->IsInsideBuffer(mappedPoint))
{
movingValue = m_MovingImageInterpolator->Evaluate(mappedPoint);
}
else
{
movingValue = 0.0;
}
sff += fixedValue * fixedValue;
smm += movingValue * movingValue;
sfm += fixedValue * movingValue;
for (unsigned int dim = 0; dim < ImageDimension; ++dim)
{
double differential = fixedGradient[dim];
derivativeF[dim] += fixedValue * differential;
derivativeM[dim] += movingValue * differential;
}
}
}
double updatenorm = 0.0;
if ((sff * smm) != 0.0)
{
double factor = 1.0 / vcl_sqrt(sff * smm);
for (unsigned int i = 0; i < ImageDimension; ++i)
{
update[i] = factor * (derivativeF[i] - (sfm / smm) * derivativeM[i]);
updatenorm += (update[i] * update[i]);
}
updatenorm = vcl_sqrt(updatenorm);
m_MetricTotal += sfm * factor;
this->m_Energy += sfm * factor;
}
else
{
for (unsigned int i = 0; i < ImageDimension; ++i)
{
update[i] = 0.0;
}
updatenorm = 1.0;
}
// if ( fixedValue > 0.40 && movingValue > 0.40) std::cout << " update norm " << updatenorm;
if (this->GetNormalizeGradient() && updatenorm != 0.0)
{
update /= (updatenorm);
}
return update * this->m_GradientStep;
}
} // end namespace otbs
#endif
|