/usr/include/ITK-4.9/itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader.hxx is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.
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 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader_hxx
#define itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader_hxx
#include "itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader.h"
namespace itk
{
template< typename TDomainPartitioner, typename TImageToImageMetric, typename TDemonsMetric >
void
DemonsImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric, TDemonsMetric >
::BeforeThreadedExecution()
{
Superclass::BeforeThreadedExecution();
/* Store the casted pointer to avoid dynamic casting in tight loops. */
this->m_DemonsAssociate = dynamic_cast<TDemonsMetric*>( this->m_Associate );
if( this->m_DemonsAssociate == ITK_NULLPTR )
{
itkExceptionMacro("Dynamic casting of associate pointer failed.");
}
}
template< typename TDomainPartitioner, typename TImageToImageMetric, typename TDemonsMetric >
bool
DemonsImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric, TDemonsMetric >
::ProcessPoint( const VirtualIndexType &,
const VirtualPointType &,
const FixedImagePointType &,
const FixedImagePixelType & fixedImageValue,
const FixedImageGradientType & fixedImageGradient,
const MovingImagePointType &,
const MovingImagePixelType & movingImageValue,
const MovingImageGradientType & movingImageGradient,
MeasureType & metricValueReturn,
DerivativeType & localDerivativeReturn,
const ThreadIdType ) const
{
/* Metric value */
const InternalComputationValueType speedValue = fixedImageValue - movingImageValue;
const InternalComputationValueType sqr_speedValue = vnl_math_sqr( speedValue );
metricValueReturn = sqr_speedValue;
if( ! this->GetComputeDerivative() )
{
return true;
}
/* Derivative */
InternalComputationValueType gradientSquaredMagnitude = 0;
const FixedImageGradientType* gradient;
SizeValueType numberOfDimensions;
if( this->m_DemonsAssociate->GetGradientSourceIncludesFixed() )
{
gradient = &fixedImageGradient;
numberOfDimensions = ImageToImageMetricv4Type::FixedImageDimension;
}
else
{
gradient = &movingImageGradient;
numberOfDimensions = ImageToImageMetricv4Type::MovingImageDimension;
}
for ( ImageDimensionType j = 0; j < numberOfDimensions; j++ )
{
gradientSquaredMagnitude += vnl_math_sqr( (*gradient)[j] );
}
/*
* In the original equation the denominator is defined as (g-f)^2 + grad_mag^2.
* However there is a mismatch in units between the two terms.
* The units for the second term is intensity^2/mm^2 while the
* units for the first term is intensity^2. This mismatch is particularly
* problematic when the fixed image does not have unit spacing.
* In this implemenation, we normalize the first term by a factor K,
* such that denominator = (g-f)^2/K + grad_mag^2
* where K = mean square spacing to compensate for the mismatch in units.
*/
const InternalComputationValueType denominator = sqr_speedValue / this->m_DemonsAssociate->m_Normalizer + gradientSquaredMagnitude;
if ( vnl_math_abs(speedValue) < this->m_DemonsAssociate->GetIntensityDifferenceThreshold() ||
denominator < this->m_DemonsAssociate->GetDenominatorThreshold() )
{
localDerivativeReturn.Fill( NumericTraits<DerivativeValueType>::ZeroValue() );
return true;
}
for ( SizeValueType p = 0; p < this->GetCachedNumberOfLocalParameters(); p++ )
{
localDerivativeReturn[p] = speedValue * (*gradient)[p] / denominator;
}
return true;
}
} // end namespace itk
#endif
|