34#ifndef AIMS_SIGNALFILTER_FILTERINGFUNCTION_LINEAR_D_H
35#define AIMS_SIGNALFILTER_FILTERINGFUNCTION_LINEAR_D_H
39#include <aims/connectivity/structuring_element.h>
42#include <cartodata/volume/volume.h>
44#include <cartobase/config/verbose.h>
45#include <cartobase/smart/rcptr.h>
63 static bool initialized =
false;
73 std::map<std::string,carto::rc_ptr<LinearFilteringFunction<T> > > &
76 static std::map<std::string,carto::rc_ptr<LinearFilteringFunction<T> > > m;
82 const std::string & name,
94 std::set<std::string> s;
95 typename std::map<std::string,carto::rc_ptr<LinearFilteringFunction<T> > >
::const_iterator i, e =
_map().end();
96 for( i=
_map().begin(); i!=e; ++i )
101 template <
typename T>
103 const std::string & name,
108 typename std::map<std::string,carto::rc_ptr<LinearFilteringFunction<T> > >
::const_iterator i;
109 i =
_map().find( name );
110 if( i ==
_map().end() )
124 template <
typename T>
125 GaborFilterFunc<T>::GaborFilterFunc(
const GaborFilterFunc<T> & other ):
140 template <
typename T>
141 GaborFilterFunc<T>::~GaborFilterFunc()
144 template <
typename T>
145 GaborFilterFunc<T> & GaborFilterFunc<T>::operator=(
const GaborFilterFunc<T> & other )
148 _init = other._init ;
158 _kernel = carto::VolumeRef<double>(
new carto::Volume<double>( *(other._kernel) ) );
163 template <
typename T>
164 void GaborFilterFunc<T>::setOptions(
const carto::Object & options )
179 if( options->hasProperty(
"sigma" ) )
180 _sigma = (double)options->getProperty(
"sigma" )->getScalar();
181 if( options->hasProperty(
"theta" ) )
182 _theta = (double)options->getProperty(
"theta" )->getScalar();
183 if( options->hasProperty(
"lambda" ) )
184 _lambda = (double)options->getProperty(
"lambda" )->getScalar();
185 if( options->hasProperty(
"psi" ) )
186 _psi = (double)options->getProperty(
"psi" )->getScalar();
187 if( options->hasProperty(
"gamma" ) )
188 _gamma = (double)options->getProperty(
"gamma" )->getScalar();
189 if( options->hasProperty(
"real" ) )
190 _real = (bool)options->getProperty(
"real" )->getScalar();
191 if( options->hasProperty(
"nstd" ) )
192 _nstd = (int)options->getProperty(
"nstd" )->getScalar();
193 if( options->hasProperty(
"voxel_size" ) )
194 options->getProperty(
"voxel_size",
_voxelsize );
199 std::cout <<
"Gabor Filter created with parameters:" << std::endl
200 <<
"- sigma: " <<
_sigma <<
" mm" << std::endl
201 <<
"- theta: " <<
_theta <<
"°" << std::endl
202 <<
"- lambda: " <<
_lambda <<
" mm" << std::endl
203 <<
"- psi: " <<
_psi <<
"°" << std::endl
204 <<
"- gamma: " <<
_gamma << std::endl
205 <<
"- return " << (
_real ?
"real part" :
"imaginary part" ) << std::endl
206 <<
"- nstd: " <<
_nstd << std::endl
213 template <
typename T>
214 void GaborFilterFunc<T>::updateOptions(
const carto::Object & options )
216 bool changed =
false;
220 std::vector<float> oldv;
224 if( options->hasProperty(
"sigma" ) ) {
226 _sigma = (double)options->getProperty(
"sigma" )->getScalar();
230 if( options->hasProperty(
"theta" ) ) {
232 _theta = (double)options->getProperty(
"theta" )->getScalar();
236 if( options->hasProperty(
"lambda" ) ) {
238 _lambda = (double)options->getProperty(
"lambda" )->getScalar();
242 if( options->hasProperty(
"psi" ) ) {
244 _psi = (double)options->getProperty(
"psi" )->getScalar();
248 if( options->hasProperty(
"gamma" ) ) {
250 _gamma = (double)options->getProperty(
"gamma" )->getScalar();
254 if( options->hasProperty(
"real" ) ) {
256 _real = (bool)options->getProperty(
"real" )->getScalar();
260 if( options->hasProperty(
"nstd" ) ) {
262 _nstd = (int)options->getProperty(
"nstd" )->getScalar();
266 if( options->hasProperty(
"voxel_size" ) ) {
268 options->getProperty(
"voxel_size",
_voxelsize );
277 std::cout <<
"Gabor Filter updated with parameters:" << std::endl
278 <<
"- sigma: " <<
_sigma <<
" mm" << std::endl
279 <<
"- theta: " <<
_theta <<
"°" << std::endl
280 <<
"- lambda: " <<
_lambda <<
" mm" << std::endl
281 <<
"- psi: " <<
_psi <<
"°" << std::endl
282 <<
"- gamma: " <<
_gamma << std::endl
283 <<
"- return " << (
_real ?
"real part" :
"imaginary part" ) << std::endl
284 <<
"- nstd: " <<
_nstd << std::endl
290 template <
typename T>
291 const std::vector<int> & GaborFilterFunc<T>::getAmplitude()
const
296 template <
typename T>
inline
297 void GaborFilterFunc<T>::setKernel()
300 std::cout <<
"setKernel" << std::endl
305 double pi = 3.1415926535897;
306 std::vector<float> famplitude(2,0.);
307 famplitude[0] = std::max(
311 famplitude[1] = std::max(
324 std::cout <<
"- amplitude: "
333 double offsetx = (double)(
_kernel->getSizeX())/2;
334 double offsety = (double)(
_kernel->getSizeY())/2;
336 for( int32_t y=0; y<
_kernel->getSizeY(); ++y )
337 for( int32_t x=0; x<
_kernel->getSizeX(); ++x )
343 _kernel(x,y) = std::exp( ( std::pow(xp,2) +
346 ( -2. * std::pow(
_sigma,2) ) );
356 template <
typename T>
inline
357 T GaborFilterFunc<T>::execute(
const carto::VolumeRef<T> & volume )
const
363 for( int32_t y=0; y<volume->
getSizeY(); ++y )
364 for( int32_t x=0; x<volume->
getSizeX(); ++x )
365 result +=
_kernel(x,y) * volume(x,y);
virtual void setOptions(const carto::Object &)
Set the parameters of the filters If a parameter value is not set in the options object,...
static std::map< std::string, carto::rc_ptr< LinearFilteringFunction< T > > > & _map()
static std::set< std::string > names()
static LinearFilteringFunction< T > * create(const std::string &name, carto::Object options=carto::none())
static void registerFunction(const std::string &name, const LinearFilteringFunction< T > &func)
Base class for linear filtering functions.
virtual LinearFilteringFunction< T > * clone() const =0
clone
std::vector< int > _amplitude
carto::VolumeRef< double > _kernel
std::vector< float > _voxelsize