My Project
2d/interpolator.hh
Go to the documentation of this file.
1/* -*- mia-c++ -*-
2 *
3 * This file is part of MIA - a toolbox for medical image analysis
4 * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5 *
6 * MIA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21/*
22 The filter routines for splines and omoms is based on code by
23 Philippe Thevenaz http://bigwww.epfl.ch/thevenaz/interpolation/
24 see also:
25
26 [1] M. Unser,
27 "Splines: A Perfect Fit for Signal and Image Processing,"
28 IEEE Signal Processing Magazine, vol. 16, no. 6, pp. 22-38,
29 November 1999.
30 [2] M. Unser, A. Aldroubi and M. Eden,
31 "B-Spline Signal Processing: Part I--Theory,"
32 IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 821-832,
33 February 1993.
34 [3] M. Unser, A. Aldroubi and M. Eden,
35 "B-Spline Signal Processing: Part II--Efficient Design and Applications,"
36 IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 834-848,
37 February 1993.
38*/
39
40#ifndef mia_2d_interpolator_hh
41#define mia_2d_interpolator_hh
42
43#include <vector>
46#include <mia/2d/image.hh>
47
48
50
54template <typename T>
55struct max_hold_type<T2DVector<T>> {
56 typedef T2DVector<double> type;
57
58
59};
61
65template <class U>
66struct coeff_map<T2DVector<U>> {
67 typedef T2DVector<U> value_type;
68 typedef C2DDVector coeff_type;
69};
70
72
73
77struct C2DWeightCache {
80
81 C2DWeightCache(int kernel_size,
82 const CSplineBoundaryCondition& xbc,
83 const CSplineBoundaryCondition& ybc);
84};
86
97template <class T>
99{
100public:
108
119
121
127 C2DWeightCache create_cache() const;
128
129
136 T operator () (const C2DFVector& x) const;
137
138
139 T operator () (const C2DFVector& x, C2DWeightCache& cache) const;
140
148
154
159
160protected:
162 typedef std::vector< typename TCoeff2D::value_type > coeff_vector;
163private:
164
165 void prefilter(const T2DDatafield<T>& image);
166
167 typename TCoeff2D::value_type evaluate() const;
168
169 TCoeff2D m_coeff;
170 C2DBounds m_size2;
171 PSplineKernel m_kernel;
172 PSplineBoundaryCondition m_x_boundary;
173 PSplineBoundaryCondition m_y_boundary;
174 typename T2DDatafield<T>::value_type m_min;
175 typename T2DDatafield<T>::value_type m_max;
176
177 mutable CMutex m_cache_lock;
178 mutable C2DWeightCache m_cache;
179
180
181};
182
190{
191public:
197 C2DInterpolatorFactory(const std::string& kernel, const std::string& boundary_conditions);
198
199
206
212 C2DInterpolatorFactory(PSplineKernel kernel, const std::string& boundary_conditions);
213
221
224
227
229
238 template <class T>
239 T2DInterpolator<T> *create(const T2DDatafield<T>& src) const
240 __attribute__ ((warn_unused_result));
241
242
246 const CSplineKernel *get_kernel() const;
247
248private:
249 PSplineKernel m_kernel;
252};
253
255typedef std::shared_ptr<C2DInterpolatorFactory > P2DInterpolatorFactory;
256
257
258// implementation
259
260template <class T>
262{
263 return new T2DInterpolator<T>(src, m_kernel, *m_xbc, *m_ybc);
264}
265
267
268#endif
std::shared_ptr< C2DInterpolatorFactory > P2DInterpolatorFactory
Pointer type for the 2D interpolationfactory.
The factory to create an interpolator from some input data.
C2DInterpolatorFactory(PSplineKernel kernel, const std::string &boundary_conditions)
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
C2DInterpolatorFactory(const std::string &kernel, const std::string &boundary_conditions)
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
C2DInterpolatorFactory(const C2DInterpolatorFactory &o)
Copy constructor.
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &boundary_conditions)
const CSplineKernel * get_kernel() const
virtual ~C2DInterpolatorFactory()
Abstract base class for B-spline interpolation boundary conditions.
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:46
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:90
The base class for 2D interpolators that use some kind of spacial convolution.
std::vector< typename TCoeff2D::value_type > coeff_vector
helper class for the coefficient field
const TCoeff2D & get_coefficients() const
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
C2DWeightCache create_cache() const
T2DVector< T > derivative_at(const C2DFVector &x) const
T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel)
a 2D vector
Definition: 2d/vector.hh:47
#define EXPORT_2D
Definition: defines2d.hh:37
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
std::shared_ptr< CSplineKernel > PSplineKernel
std::mutex CMutex