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>
44 #include <mia/core/splinekernel.hh>
46 #include <mia/2d/image.hh>
47 
48 
50 
54 template <typename T>
55 struct max_hold_type<T2DVector<T> > {
56  typedef T2DVector<double> type;
57 
58 
59 };
61 
65 template <class U>
66 struct coeff_map<T2DVector<U> > {
67  typedef T2DVector<U> value_type;
68  typedef C2DDVector coeff_type;
69 };
70 
72 
73 
77 struct C2DWeightCache {
80 
81  C2DWeightCache(int kernel_size,
82  const CSplineBoundaryCondition& xbc,
83  const CSplineBoundaryCondition& ybc);
84 };
86 
97 template <class T>
99 public:
106  T2DInterpolator(const T2DDatafield<T>& data, PSplineKernel kernel);
107 
116  T2DInterpolator(const T2DDatafield<T>& data, PSplineKernel kernel,
117  const CSplineBoundaryCondition& xbc, const CSplineBoundaryCondition& ybc);
118 
119  ~T2DInterpolator();
120 
126  C2DWeightCache create_cache() const;
127 
128 
135  T operator () (const C2DFVector& x) const;
136 
137 
138  T operator () (const C2DFVector& x, C2DWeightCache& cache) const;
139 
146  T2DVector<T> derivative_at(const C2DFVector& x) const;
147 
153 
157  const TCoeff2D& get_coefficients() const;
158 
159 protected:
161  typedef std::vector< typename TCoeff2D::value_type > coeff_vector;
162 private:
163 
164  void prefilter(const T2DDatafield<T>& image);
165 
166  typename TCoeff2D::value_type evaluate() const;
167 
168  TCoeff2D m_coeff;
169  C2DBounds m_size2;
170  PSplineKernel m_kernel;
171  PSplineBoundaryCondition m_x_boundary;
172  PSplineBoundaryCondition m_y_boundary;
173  typename T2DDatafield<T>::value_type m_min;
174  typename T2DDatafield<T>::value_type m_max;
175 
176  mutable CMutex m_cache_lock;
177  mutable C2DWeightCache m_cache;
178 
179 
180 };
181 
189 public:
195  C2DInterpolatorFactory(const std::string& kernel, const std::string& boundary_conditions);
196 
197 
203  C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition& boundary_conditions);
204 
210  C2DInterpolatorFactory(PSplineKernel kernel, const std::string& boundary_conditions);
211 
219 
222 
224  C2DInterpolatorFactory& operator = ( const C2DInterpolatorFactory& o);
225 
226  virtual ~C2DInterpolatorFactory();
227 
236  template <class T>
237  T2DInterpolator<T> *create(const T2DDatafield<T>& src) const
238  __attribute__ ((warn_unused_result));
239 
240 
244  const CSplineKernel* get_kernel() const;
245 
246 private:
247  PSplineKernel m_kernel;
250 };
251 
253 typedef std::shared_ptr<C2DInterpolatorFactory > P2DInterpolatorFactory;
254 
255 
256 // implementation
257 
258 template <class T>
260 {
261  return new T2DInterpolator<T>(src, m_kernel, *m_xbc, *m_ybc);
262 }
263 
265 
266 #endif
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
std::shared_ptr< C2DInterpolatorFactory > P2DInterpolatorFactory
Pointer type for the 2D interpolationfactory.
The base class for 2D interpolators that use some kind of spacial convolution.
a 2D vector
Definition: 2d/vector.hh:46
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define EXPORT_2D
Definition: defines2d.hh:37
std::shared_ptr< CSplineKernel > PSplineKernel
Abstract base class for B-spline interpolation boundary conditions.
std::vector< typename TCoeff2D::value_type > coeff_vector
helper class for the coefficient field
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:89
The factory to create an interpolator from some input data.
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:45
T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D
std::mutex CMutex
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36