Skip to content

Commit 7b4e4f9

Browse files
ENH: make DerivativeThreshold variable
1 parent 6ae35b9 commit 7b4e4f9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/itkSingleImageCostFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class ITK_EXPORT SingleImageCostFunction :
110110
itkSetConstObjectMacro( Image, ImageType );
111111
itkGetConstObjectMacro( Image, ImageType );
112112

113+
/** Get/set the DerivativeThreshold. */
114+
itkSetMacro( DerivativeThreshold, DerivativeType::ValueType );
115+
itkGetConstReferenceMacro( DerivativeThreshold, DerivativeType::ValueType );
116+
113117
/** Initialize the cost function */
114118
virtual void Initialize(void) throw ( ExceptionObject );
115119

@@ -150,6 +154,7 @@ class ITK_EXPORT SingleImageCostFunction :
150154
/** Used to define the value outside the image buffer. Important when
151155
* path points are on the edge of an image */
152156
ImagePixelType m_OutsideValue;
157+
typename DerivativeType::ValueType m_DerivativeThreshold;
153158

154159
};
155160

include/itkSingleImageCostFunction.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SingleImageCostFunction<TImage>
3333
m_Image = nullptr; // Provided by user
3434
m_Interpolator = nullptr; // Configured in Initialize()
3535
m_GradientImageFunction = nullptr; // Configured in Initialize()
36+
m_DerivativeThreshold = 15.0; // as in original implementation
3637
}
3738

3839

@@ -137,7 +138,6 @@ SingleImageCostFunction<TImage>
137138
}
138139

139140
// Convert the image function output to the cost function derivative
140-
constexpr typename DerivativeType::ValueType DerivativeThreshold = 15.0;
141141
for (unsigned int i=0; i<ImageDimension; i++)
142142
{
143143
derivative[i] = static_cast<typename DerivativeType::ValueType>( output[i] );
@@ -146,7 +146,7 @@ SingleImageCostFunction<TImage>
146146
// (indicated by very large values) which may skew the gradient.
147147
// To avoid this skewing effect, we reset gradient values larger
148148
// than a given threshold.
149-
if ( itk::Math::abs (derivative[i]) > DerivativeThreshold )
149+
if ( itk::Math::abs (derivative[i]) > m_DerivativeThreshold )
150150
{
151151
derivative[i] = 0.0;
152152
}

0 commit comments

Comments
 (0)