2d/deformer.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/>.
*
*/
#ifndef mia_2d_deformer_hh
#define mia_2d_deformer_hh
#include <mia/2d/image.hh>
#include <mia/2d/filter.hh>
#include <mia/2d/interpolator.hh>
NS_MIA_BEGIN
struct FDeformer2D: public TFilter<P2DImage> {
FDeformer2D(const C2DFVectorfield& vf, const C2DInterpolatorFactory& ipfac):
m_vf(vf),
m_ipfac(ipfac)
{
}
template <typename T>
P2DImage operator () (const T2DImage<T>& image) const
{
T2DImage<T> *timage = new T2DImage<T>(image.get_size());
std::shared_ptr<T2DInterpolator<T>> interp(m_ipfac.create(image.data()));
typename T2DImage<T>::iterator r = timage->begin();
C2DFVectorfield::const_iterator v = m_vf.begin();
for (size_t y = 0; y < image.get_size().y; ++y)
for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
*r = (*interp)(C2DFVector(x - v->x, y - v->y));
}
return P2DImage(timage);
}
template <typename T>
void operator () (const T2DImage<T>& image, T2DImage<T>& result) const
{
assert(image.get_size() == result.get_size());
std::shared_ptr<T2DInterpolator<T>> interp(m_ipfac.create(image.data()));
typename T2DImage<T>::iterator r = result.begin();
C2DFVectorfield::const_iterator v = m_vf.begin();
for (size_t y = 0; y < image.get_size().y; ++y)
for (size_t x = 0; x < image.get_size().x; ++x, ++r, ++v) {
*r = (*interp)(C2DFVector(x - v->x, y - v->y));
}
}
private:
C2DFVectorfield m_vf;
C2DInterpolatorFactory m_ipfac;
};
NS_MIA_END
#endif
filter.hh
image.hh
P2DImage
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition 2d/image.hh:120
interpolator.hh
C2DFVector
T2DVector< float > C2DFVector
float valued 2D vector
Definition 2d/vector.hh:534
C2DFVectorfield
a 2D field of floating point single accuracy 2D vectors
Definition 2d/vectorfield.hh:80
C2DImage::get_size
const C2DBounds & get_size() const
C2DInterpolatorFactory
The factory to create an interpolator from some input data.
Definition 2d/interpolator.hh:190
T2DImage
This is the template version of a 2D image that is used for holding real data.
Definition 2d/image.hh:140
T2DImage::begin
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:269
T2DImage::data
const T2DDatafield< T > & data() const
get direct access to the data field
TPluginHandler::begin
const_iterator begin() const
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
FDeformer2D::FDeformer2D
FDeformer2D(const C2DFVectorfield &vf, const C2DInterpolatorFactory &ipfac)
Definition 2d/deformer.hh:45
FDeformer2D::operator()
P2DImage operator()(const T2DImage< T > &image) const
Definition 2d/deformer.hh:58
TFilter
base class for all filer type functors.
Definition core/filter.hh:70