/usr/include/ITK-4.5/itkBSplineInterpolateImageFunction.h is in libinsighttoolkit4-dev 4.5.0-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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | /*=========================================================================
*
* 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.
*
*=========================================================================*/
/*=========================================================================
*
* Portions of this file are subject to the VTK Toolkit Version 3 copyright.
*
* Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
*
* For complete copyright, license and disclaimer of warranty information
* please refer to the NOTICE file at the top of the ITK source tree.
*
*=========================================================================*/
#ifndef __itkBSplineInterpolateImageFunction_h
#define __itkBSplineInterpolateImageFunction_h
#include <vector>
#include "itkInterpolateImageFunction.h"
#include "vnl/vnl_matrix.h"
#include "itkBSplineDecompositionImageFilter.h"
#include "itkConceptChecking.h"
#include "itkCovariantVector.h"
namespace itk
{
/** \class BSplineInterpolateImageFunction
* \brief Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
*
* This class defines N-Dimension B-Spline transformation.
* It is based on:
* [1] M. Unser,
* "Splines: A Perfect Fit for Signal and Image Processing,"
* IEEE Signal Processing Magazine, vol. 16, no. 6, pp. 22-38,
* November 1999.
* [2] M. Unser, A. Aldroubi and M. Eden,
* "B-Spline Signal Processing: Part I--Theory,"
* IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 821-832,
* February 1993.
* [3] M. Unser, A. Aldroubi and M. Eden,
* "B-Spline Signal Processing: Part II--Efficient Design and Applications,"
* IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 834-848,
* February 1993.
* And code obtained from bigwww.epfl.ch by Philippe Thevenaz
*
* The B spline coefficients are calculated through the
* BSplineDecompositionImageFilter
*
* Limitations: Spline order must be between 0 and 5.
* Spline order must be set before setting the image.
* Uses mirror boundary conditions.
* Requires the same order of Spline for each dimension.
* Spline is determined in all dimensions, cannot selectively
* pick dimension for calculating spline.
*
* \sa BSplineDecompositionImageFilter
*
* \ingroup ImageFunctions
* \ingroup ITKImageFunction
*
* \wiki
* \wikiexample{ImageProcessing/Upsampling,Upsampling an image}
* \endwiki
*/
template<
typename TImageType,
typename TCoordRep = double,
typename TCoefficientType = double >
class BSplineInterpolateImageFunction:
public InterpolateImageFunction< TImageType, TCoordRep >
{
public:
/** Standard class typedefs. */
typedef BSplineInterpolateImageFunction Self;
typedef InterpolateImageFunction< TImageType, TCoordRep > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(BSplineInterpolateImageFunction, InterpolateImageFunction);
/** New macro for creation of through a Smart Pointer */
itkNewMacro(Self);
/** OutputType typedef support. */
typedef typename Superclass::OutputType OutputType;
/** InputImageType typedef support. */
typedef typename Superclass::InputImageType InputImageType;
/** Dimension underlying input image. */
itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
/** Index typedef support. */
typedef typename Superclass::IndexType IndexType;
/** ContinuousIndex typedef support. */
typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
/** PointType typedef support */
typedef typename Superclass::PointType PointType;
/** Iterator typedef support */
typedef ImageLinearIteratorWithIndex< TImageType > Iterator;
/** Internal Coefficient typedef support */
typedef TCoefficientType CoefficientDataType;
typedef Image< CoefficientDataType,
itkGetStaticConstMacro(ImageDimension) >
CoefficientImageType;
/** Define filter for calculating the BSpline coefficients */
typedef BSplineDecompositionImageFilter< TImageType, CoefficientImageType > CoefficientFilter;
typedef typename CoefficientFilter::Pointer CoefficientFilterPointer;
/** Derivative typedef support */
typedef CovariantVector< OutputType,
itkGetStaticConstMacro(ImageDimension) >
CovariantVectorType;
/** Evaluate the function at a ContinuousIndex position.
*
* Returns the B-Spline interpolated image intensity at a
* specified point position. No bounds checking is done.
* The point is assume to lie within the image buffer.
*
* ImageFunction::IsInsideBuffer() can be used to check bounds before
* calling the method. */
virtual OutputType Evaluate(const PointType & point) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
// No thread info passed in, so call method that doesn't need thread ID.
return ( this->EvaluateAtContinuousIndex(index) );
}
virtual OutputType Evaluate(const PointType & point,
ThreadIdType threadID) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
return ( this->EvaluateAtContinuousIndex(index, threadID) );
}
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &
index) const
{
// Don't know thread information, make evaluateIndex, weights on the stack.
// Slower, but safer.
vnl_matrix< long > evaluateIndex( ImageDimension, ( m_SplineOrder + 1 ) );
vnl_matrix< double > weights( ImageDimension, ( m_SplineOrder + 1 ) );
// Pass evaluateIndex, weights by reference. They're only good as long
// as this method is in scope.
return this->EvaluateAtContinuousIndexInternal(index,
evaluateIndex,
weights);
}
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &
index,
ThreadIdType threadID) const;
CovariantVectorType EvaluateDerivative(const PointType & point) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
// No thread info passed in, so call method that doesn't need thread ID.
return ( this->EvaluateDerivativeAtContinuousIndex(index) );
}
CovariantVectorType EvaluateDerivative(const PointType & point,
ThreadIdType threadID) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
return ( this->EvaluateDerivativeAtContinuousIndex(index, threadID) );
}
CovariantVectorType EvaluateDerivativeAtContinuousIndex(
const ContinuousIndexType & x) const
{
// Don't know thread information, make evaluateIndex, weights,
// weightsDerivative
// on the stack.
// Slower, but safer.
vnl_matrix< long > evaluateIndex( ImageDimension, ( m_SplineOrder + 1 ) );
vnl_matrix< double > weights( ImageDimension, ( m_SplineOrder + 1 ) );
vnl_matrix< double > weightsDerivative( ImageDimension, ( m_SplineOrder + 1 ) );
// Pass evaluateIndex, weights, weightsDerivative by reference. They're only
// good
// as long as this method is in scope.
return this->EvaluateDerivativeAtContinuousIndexInternal(x,
evaluateIndex,
weights,
weightsDerivative);
}
CovariantVectorType EvaluateDerivativeAtContinuousIndex(
const ContinuousIndexType & x,
ThreadIdType threadID) const;
void EvaluateValueAndDerivative(const PointType & point,
OutputType & value,
CovariantVectorType & deriv) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
// No thread info passed in, so call method that doesn't need thread ID.
this->EvaluateValueAndDerivativeAtContinuousIndex(index,
value,
deriv);
}
void EvaluateValueAndDerivative(const PointType & point,
OutputType & value,
CovariantVectorType & deriv,
ThreadIdType threadID) const
{
ContinuousIndexType index;
this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point,
index);
this->EvaluateValueAndDerivativeAtContinuousIndex(index,
value,
deriv,
threadID);
}
void EvaluateValueAndDerivativeAtContinuousIndex(
const ContinuousIndexType & x,
OutputType & value,
CovariantVectorType & deriv
) const
{
// Don't know thread information, make evaluateIndex, weights,
// weightsDerivative
// on the stack.
// Slower, but safer.
vnl_matrix< long > evaluateIndex( ImageDimension, ( m_SplineOrder + 1 ) );
vnl_matrix< double > weights( ImageDimension, ( m_SplineOrder + 1 ) );
vnl_matrix< double > weightsDerivative( ImageDimension, ( m_SplineOrder + 1 ) );
// Pass evaluateIndex, weights, weightsDerivative by reference. They're only
// good
// as long as this method is in scope.
this->EvaluateValueAndDerivativeAtContinuousIndexInternal(x,
value,
deriv,
evaluateIndex,
weights,
weightsDerivative);
}
void EvaluateValueAndDerivativeAtContinuousIndex(
const ContinuousIndexType & x,
OutputType & value,
CovariantVectorType & deriv,
ThreadIdType threadID) const;
/** Get/Sets the Spline Order, supports 0th - 5th order splines. The default
* is a 3rd order spline. */
void SetSplineOrder(unsigned int SplineOrder);
itkGetConstMacro(SplineOrder, int);
void SetNumberOfThreads(ThreadIdType numThreads);
itkGetConstMacro(NumberOfThreads, ThreadIdType);
/** Set the input image. This must be set by the user. */
virtual void SetInputImage(const TImageType *inputData);
/** The UseImageDirection flag determines whether image derivatives are
* computed with respect to the image grid or with respect to the physical
* space. When this flag is ON the derivatives are computed with respect to
* the coodinate system of physical space. The difference is whether we take
* into account the image Direction or not. The flag ON will take into
* account the image direction and will result in an extra matrix
* multiplication compared to the amount of computation performed when the
* flag is OFF.
* The default value of this flag is On.
*/
itkSetMacro(UseImageDirection, bool);
itkGetConstMacro(UseImageDirection, bool);
itkBooleanMacro(UseImageDirection);
protected:
/** The following methods take working space (evaluateIndex, weights, weightsDerivative)
* that is managed by the caller. If threadID is known, the working variables are looked
* up in the thread indexed arrays. If threadID is not known, working variables are made
* on the stack and passed to these methods. The stack allocation should be ok since
* these methods do not store the working variables, i.e. they are not expected to
* be available beyond the scope of the function call.
*
* This was done to allow for two types of re-entrancy. The first is when a threaded
* filter, e.g. InterpolateImagePointsFilter calls EvaluateAtContinuousIndex from multiple
* threads without passing a threadID. So, EvaluateAtContinuousIndex must be thread safe.
* This is handled with the stack-based allocation of the working space.
*
* The second form of re-entrancy involves methods that call EvaluateAtContinuousIndex
* from multiple threads, but pass a threadID. In this case, we can gain a little efficiency
* (hopefully) by looking up pre-allocated working space in arrays that are indexed by thread.
* The efficiency gain is likely dependent on the size of the working variables, which are
* in-turn dependent on the dimensionality of the image and the order of the spline.
*/
virtual OutputType EvaluateAtContinuousIndexInternal(const ContinuousIndexType & index,
vnl_matrix< long > & evaluateIndex,
vnl_matrix< double > & weights) const;
virtual void EvaluateValueAndDerivativeAtContinuousIndexInternal(const ContinuousIndexType & x,
OutputType & value,
CovariantVectorType & derivativeValue,
vnl_matrix< long > & evaluateIndex,
vnl_matrix< double > & weights,
vnl_matrix< double > & weightsDerivative
) const;
virtual CovariantVectorType EvaluateDerivativeAtContinuousIndexInternal(const ContinuousIndexType & x,
vnl_matrix< long > & evaluateIndex,
vnl_matrix< double > & weights,
vnl_matrix< double > & weightsDerivative
) const;
BSplineInterpolateImageFunction();
~BSplineInterpolateImageFunction();
void PrintSelf(std::ostream & os, Indent indent) const;
// These are needed by the smoothing spline routine.
// temp storage for processing of Coefficients
std::vector< CoefficientDataType > m_Scratch;
// Image size
typename TImageType::SizeType m_DataLength;
// User specified spline order (3rd or cubic is the default)
unsigned int m_SplineOrder;
// Spline coefficients
typename CoefficientImageType::ConstPointer m_Coefficients;
private:
BSplineInterpolateImageFunction(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented
/** Determines the weights for interpolation of the value x */
void SetInterpolationWeights(const ContinuousIndexType & x,
const vnl_matrix< long > & EvaluateIndex,
vnl_matrix< double > & weights,
unsigned int splineOrder) const;
/** Determines the weights for the derivative portion of the value x */
void SetDerivativeWeights(const ContinuousIndexType & x,
const vnl_matrix< long > & EvaluateIndex,
vnl_matrix< double > & weights,
unsigned int splineOrder) const;
/** Precomputation for converting the 1D index of the interpolation
* neighborhood to an N-dimensional index. */
void GeneratePointsToIndex();
/** Determines the indices to use give the splines region of support */
void DetermineRegionOfSupport(vnl_matrix< long > & evaluateIndex,
const ContinuousIndexType & x,
unsigned int splineOrder) const;
/** Set the indices in evaluateIndex at the boundaries based on mirror
* boundary conditions. */
void ApplyMirrorBoundaryConditions(vnl_matrix< long > & evaluateIndex,
unsigned int splineOrder) const;
Iterator m_CIterator; // Iterator for
// traversing spline
// coefficients.
unsigned long m_MaxNumberInterpolationPoints; // number of
// neighborhood
// points used for
// interpolation
std::vector< IndexType > m_PointsToIndex; // Preallocation of
// interpolation
// neighborhood
// indices
CoefficientFilterPointer m_CoefficientFilter;
// flag to take or not the image direction into account when computing the
// derivatives.
bool m_UseImageDirection;
ThreadIdType m_NumberOfThreads;
vnl_matrix< long > * m_ThreadedEvaluateIndex;
vnl_matrix< double > *m_ThreadedWeights;
vnl_matrix< double > *m_ThreadedWeightsDerivative;
};
} // namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkBSplineInterpolateImageFunction.hxx"
#endif
#endif
|