2d/interpolator.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
/*
The filter routines for splines and omoms is based on code by
Philippe Thevenaz http://bigwww.epfl.ch/thevenaz/interpolation/
see also:
[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.
*/
#ifndef mia_2d_interpolator_hh
#define mia_2d_interpolator_hh
#include <vector>
#include <mia/core/splinekernel.hh>
#include <mia/core/boundary_conditions.hh>
#include <mia/2d/image.hh>
NS_MIA_BEGIN
template <typename T>
struct max_hold_type<T2DVector<T>> {
typedef T2DVector<double> type;
};
template <class U>
struct coeff_map<T2DVector<U>> {
typedef T2DVector<U> value_type;
typedef C2DDVector coeff_type;
};
struct C2DWeightCache {
CSplineKernel::SCache x;
CSplineKernel::SCache y;
C2DWeightCache(int kernel_size,
const CSplineBoundaryCondition& xbc,
const CSplineBoundaryCondition& ybc);
};
template <class T>
class EXPORT_2D T2DInterpolator
{
public:
T2DInterpolator(const T2DDatafield<T>& data, PSplineKernel kernel);
T2DInterpolator(const T2DDatafield<T>& data, PSplineKernel kernel,
const CSplineBoundaryCondition& xbc, const CSplineBoundaryCondition& ybc);
~T2DInterpolator();
C2DWeightCache create_cache() const;
T operator () (const C2DFVector& x) const;
T operator () (const C2DFVector& x, C2DWeightCache& cache) const;
T2DVector<T> derivative_at(const C2DFVector& x) const;
typedef T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D;
const TCoeff2D& get_coefficients() const;
protected:
typedef std::vector< typename TCoeff2D::value_type > coeff_vector;
private:
void prefilter(const T2DDatafield<T>& image);
typename TCoeff2D::value_type evaluate() const;
TCoeff2D m_coeff;
C2DBounds m_size2;
PSplineKernel m_kernel;
PSplineBoundaryCondition m_x_boundary;
PSplineBoundaryCondition m_y_boundary;
typename T2DDatafield<T>::value_type m_min;
typename T2DDatafield<T>::value_type m_max;
mutable CMutex m_cache_lock;
mutable C2DWeightCache m_cache;
};
class EXPORT_2D C2DInterpolatorFactory
{
public:
C2DInterpolatorFactory(const std::string& kernel, const std::string& boundary_conditions);
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition& boundary_conditions);
C2DInterpolatorFactory(PSplineKernel kernel, const std::string& boundary_conditions);
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition& xbc, const CSplineBoundaryCondition& ybc);
C2DInterpolatorFactory(const C2DInterpolatorFactory& o);
C2DInterpolatorFactory& operator = ( const C2DInterpolatorFactory& o);
virtual ~C2DInterpolatorFactory();
template <class T>
T2DInterpolator<T> *create(const T2DDatafield<T>& src) const
__attribute__ ((warn_unused_result));
const CSplineKernel *get_kernel() const;
private:
PSplineKernel m_kernel;
PSplineBoundaryCondition m_xbc;
PSplineBoundaryCondition m_ybc;
};
typedef std::shared_ptr<C2DInterpolatorFactory > P2DInterpolatorFactory;
// implementation
template <class T>
T2DInterpolator<T> *C2DInterpolatorFactory::create(const T2DDatafield<T>& src) const
{
return new T2DInterpolator<T>(src, m_kernel, *m_xbc, *m_ybc);
}
NS_MIA_END
#endif
image.hh
P2DInterpolatorFactory
std::shared_ptr< C2DInterpolatorFactory > P2DInterpolatorFactory
Pointer type for the 2D interpolationfactory.
Definition 2d/interpolator.hh:255
C2DBounds
T2DVector< unsigned int > C2DBounds
unsigned int valued 2D vector - used as 2D size parameter
Definition 2d/vector.hh:540
C2DFVector
T2DVector< float > C2DFVector
float valued 2D vector
Definition 2d/vector.hh:534
C2DDVector
T2DVector< double > C2DDVector
double valued 2D vector
Definition 2d/vector.hh:537
boundary_conditions.hh
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const std::string &boundary_conditions)
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(const std::string &kernel, const std::string &boundary_conditions)
C2DInterpolatorFactory::create
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
Definition 2d/interpolator.hh:261
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(const C2DInterpolatorFactory &o)
Copy constructor.
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &boundary_conditions)
C2DInterpolatorFactory::get_kernel
const CSplineKernel * get_kernel() const
C2DInterpolatorFactory::~C2DInterpolatorFactory
virtual ~C2DInterpolatorFactory()
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition boundary_conditions.hh:53
CSplineKernel
Base class for all spline based interpolation kernels.
Definition splinekernel.hh:46
T2DDatafield
A class to hold data on a regular 2D grid.
Definition 2d/datafield.hh:90
T2DInterpolator
The base class for 2D interpolators that use some kind of spacial convolution.
Definition 2d/interpolator.hh:99
T2DInterpolator::coeff_vector
std::vector< typename TCoeff2D::value_type > coeff_vector
helper class for the coefficient field
Definition 2d/interpolator.hh:162
T2DInterpolator::get_coefficients
const TCoeff2D & get_coefficients() const
T2DInterpolator::~T2DInterpolator
~T2DInterpolator()
T2DInterpolator::T2DInterpolator
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
T2DInterpolator::create_cache
C2DWeightCache create_cache() const
T2DInterpolator::derivative_at
T2DVector< T > derivative_at(const C2DFVector &x) const
T2DInterpolator::TCoeff2D
T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D
Definition 2d/interpolator.hh:153
T2DInterpolator::T2DInterpolator
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel)
T2DVector
a 2D vector
Definition 2d/vector.hh:47
EXPORT_2D
#define EXPORT_2D
Definition defines2d.hh:37
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
PSplineBoundaryCondition
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
Definition boundary_conditions.hh:167
PSplineKernel
std::shared_ptr< CSplineKernel > PSplineKernel
Definition splinekernel.hh:291
CMutex
std::mutex CMutex
Definition parallelcxx11.hh:34
splinekernel.hh