2d/deformer.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-2013 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 #ifndef mia_2d_deformer_hh
22 #define mia_2d_deformer_hh
23 
24 #include <mia/2d/image.hh>
25 #include <mia/2d/filter.hh>
26 #include <mia/2d/interpolator.hh>
27 
29 
30 
38 struct FDeformer2D: public TFilter<P2DImage> {
39 
46  m_vf(vf),
47  m_ipfac(ipfac)
48  {
49  }
50 
57  template <typename T>
58  P2DImage operator () (const T2DImage<T>& image) const {
59  T2DImage<T> *timage = new T2DImage<T>(image.get_size());
60 
61  std::shared_ptr<T2DInterpolator<T> > interp(m_ipfac.create(image.data()));
62 
63  typename T2DImage<T>::iterator r = timage->begin();
64  C2DFVectorfield::const_iterator v = m_vf.begin();
65 
66  for (size_t y = 0; y < image.get_size().y; ++y)
67  for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
68  *r = (*interp)(C2DFVector(x - v->x, y - v->y));
69  }
70  return P2DImage(timage);
71  }
72 
79  template <typename T>
80  void operator () (const T2DImage<T>& image, T2DImage<T>& result) const {
81  assert(image.get_size() == result.get_size());
82 
83  std::shared_ptr<T2DInterpolator<T> > interp(m_ipfac.create(image.data()));
84 
85  typename T2DImage<T>::iterator r = result.begin();
86  C2DFVectorfield::const_iterator v = m_vf.begin();
87 
88  for (size_t y = 0; y < image.get_size().y; ++y)
89  for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
90  *r = (*interp)(C2DFVector(x - v->x, y - v->y));
91  }
92  }
93 
94 private:
95  C2DFVectorfield m_vf;
96  C2DInterpolatorFactory m_ipfac;
97 };
98 
100 
101 #endif