Main Page   Namespace List   Compound List   File List   Namespace Members   Compound Members  

pass_band_filter.h

Go to the documentation of this file.
00001 #ifndef __PASS_BAND_FILTER__
00002 #define __PASS_BAND_FILTER__
00003 
00049 #include <complex>
00050 
00051 #include "function_2D.h"
00052 
00053 #include "fftw3.h"
00054 
00055 #include "fft/support.h"
00056 
00057 
00058 namespace FFT{
00059 
00060 
00062   template<typename Function>
00063   inline void difference_of_gaussians(const Function& f,
00064                                       const float     small_wave_length,
00065                                       const float     large_wave_length,
00066                                       Function* const g);
00067 
00068 
00069 
00072   template<typename Function>
00073   inline void  difference_of_gaussians(const Function& f,
00074                                        const float     small_wave_length,
00075                                        const float     large_wave_length,
00076                                        Function* const g,
00077                                        Support&        support);
00078 
00080   template<typename Function>
00081   inline void difference_of_gaussians(const Function& f,
00082                                       const float     center_wave_length,
00083                                       Function* const g);
00084 
00085 
00086 
00090   template<typename Function>
00091   inline void  difference_of_gaussians(const Function& f,
00092                                        const float     center_wave_length,
00093                                        Function* const g,
00094                                        Support&        support);
00095 
00096 
00099   template<typename Function>
00100   inline void difference_of_gaussians(const Support::buffer_type& F,
00101                                       const float     center_wave_length,
00102                                       Function* const g,
00103                                       Support&        support);
00104 
00105   
00106   
00112   template<typename Function>
00113   void difference_of_gaussians(const Support::buffer_type& F,
00114                                const float     small_wave_length,
00115                                const float     large_wave_length,
00116                                Function* const g,
00117                                Support&        support);
00118 
00119 
00120 
00121 
00123   namespace Fourier_domain{ 
00124   
00128     inline void
00129     difference_of_gaussians(const Support::buffer_type& F,
00130                             const float                 center_wave_length,
00131                             Support::buffer_type* const G,
00132                             Support&                    support);
00133   
00138     inline void
00139     difference_of_gaussians(const Support::buffer_type& F,
00140                             const float                 small_wave_length,
00141                             const float                 large_wave_length,
00142                             Support::buffer_type* const G,
00143                             Support&                    support);
00144   }
00145 
00146 
00147   
00148 
00149 /*
00150   ###########################################################
00151   ###########################################################
00152   ###########################################################
00153   ##############                               ##############
00154   ##############  I M P L E M E N T A T I O N  ##############
00155   ##############                               ##############
00156   ###########################################################
00157   ###########################################################
00158   ###########################################################
00159 */
00160 
00161   
00162 
00163 
00164   template<typename Function>
00165   void difference_of_gaussians(const Function& f,
00166                                const float     center_wave_length,
00167                                Function* const g){
00168 
00169     difference_of_gaussians(f,
00170                             center_wave_length*M_SQRT1_2*M_SQRT1_2,
00171                             center_wave_length*M_SQRT2*M_SQRT1_2,
00172                             g);
00173 
00174   }
00175 
00176 
00177 
00178   template<typename Function>
00179   void  difference_of_gaussians(const Function& f,
00180                                 const float     center_wave_length,
00181                                 Function* const g,
00182                                 Support&        support){
00183 
00184     difference_of_gaussians(f,
00185                             center_wave_length*M_SQRT1_2*M_SQRT1_2,
00186                             center_wave_length*M_SQRT2*M_SQRT1_2,
00187                             g,
00188                             support);
00189   }
00190 
00191 
00192   
00193   template<typename Function>
00194   void difference_of_gaussians(const Function& f,
00195                                const float     small_wave_length,
00196                                const float     large_wave_length,
00197                                Function* const g,
00198                                Support&        support){
00199 
00200     // We need a temporary buffer.
00201     Support::buffer_type buffer = support.create_buffer();
00202 
00203     // Store f data in the fftw structures.
00204     support.load_space_data(f);
00205     
00206     // Compute the FFT.
00207     support.space_to_frequency();
00208     
00209     // Copy the result in a safe place.
00210     support.save_frequency_data_into_buffer(buffer);
00211 
00212     difference_of_gaussians(buffer,
00213                             small_wave_length,
00214                             large_wave_length,
00215                             g,
00216                             support);
00217   }
00218 
00219 
00220   
00221   template<typename Function>
00222   void difference_of_gaussians(const Function& f,
00223                                const float     small_wave_length,
00224                                const float     large_wave_length,
00225                                Function* const g){
00226 
00227     Support s(f.x_size(),f.y_size());
00228 
00229     difference_of_gaussians(f,small_wave_length,large_wave_length,g,s);
00230   }
00231 
00232 
00233 
00234   
00235   template<typename Function>
00236   void difference_of_gaussians(const Support::buffer_type& F,
00237                                const float                 center_wave_length,
00238                                Function* const             g,
00239                                Support&                    support){
00240 
00241     difference_of_gaussians(F,
00242                             center_wave_length*M_SQRT1_2,
00243                             center_wave_length*M_SQRT2,
00244                             g,
00245                             support);
00246   }
00247 
00248   
00249   
00250 
00251   
00252   
00253   template<typename Function>
00254   void difference_of_gaussians(const Support::buffer_type& F,
00255                                const float                 small_wave_length,
00256                                const float                 large_wave_length,
00257                                Function* const             g,
00258                                Support&                    support){
00259 
00260     using namespace Function_2D;
00261 
00262 
00263     // Type definition
00264     typedef float                              real_type;
00265     typedef std::complex<float>                complex_type;
00266     typedef FFT_normalized_gaussian            gaussian_type;
00267     typedef Minus<gaussian_type,gaussian_type> dog_type;
00268 
00269     // Creation of the data structures
00270     Array_2D<complex_type> dog_kernel(support.x_frequency_size(),
00271                                       support.y_frequency_size(),
00272                                       complex_type());
00273 
00274     const real_type width  = static_cast<real_type>(support.x_space_size());
00275     const real_type height = static_cast<real_type>(support.y_space_size());
00276     
00277     const real_type small_sigma_x = 2 * width / small_wave_length;
00278     const real_type small_sigma_y = 2 * height / small_wave_length;
00279 
00280     const real_type large_sigma_x = 2 * width / large_wave_length;
00281     const real_type large_sigma_y = 2 * height / large_wave_length;
00282 
00283     gaussian_type small_gaussian(0,0,small_sigma_x,small_sigma_y,0);
00284     gaussian_type large_gaussian(0,0,large_sigma_x,large_sigma_y,0);
00285 
00286     const dog_type dog(small_gaussian,large_gaussian);
00287 
00288     // Creation of DoG kernel
00289     FFT::fill_real_part(dog,&dog_kernel);
00290 
00291     // Load the data in the FFT engine
00292     support.load_frequency_data(dog_kernel);
00293 
00294     // Multiplication "in place" in the frequency space.    
00295     support.multiply_frequency_data_by_buffer(F,true);
00296 
00297     // Compute inverse FFT transform.
00298     support.frequency_to_space();
00299 
00300     // Return data into the original structures    
00301     support.save_space_data(g);
00302   }
00303 
00304 
00305 
00306   namespace Fourier_domain{ 
00307 
00308     void difference_of_gaussians(const Support::buffer_type& F,
00309                                  const float                 center_wave_length,
00310                                  Support::buffer_type* const G,
00311                                  Support&                    support){
00312 
00313       FFT::Fourier_domain::difference_of_gaussians(F,
00314                                                    center_wave_length*M_SQRT1_2*M_SQRT1_2,
00315                                                    center_wave_length*M_SQRT2*M_SQRT1_2,
00316                                                    G,
00317                                                    support);
00318     }
00319 
00320 
00321 
00322 
00324     void difference_of_gaussians(const Support::buffer_type& F,
00325                                  const float                 small_wave_length,
00326                                  const float                 large_wave_length,
00327                                  Support::buffer_type* const G,
00328                                  Support&                    support){
00329 
00330       using namespace Function_2D;
00331 
00332 
00333       // Type definition
00334       typedef float                              real_type;
00335       typedef std::complex<float>                complex_type;
00336       typedef FFT_normalized_gaussian            gaussian_type;
00337       typedef Minus<gaussian_type,gaussian_type> dog_type;
00338 
00339       // Creation of the data structures
00340       Array_2D<complex_type> dog_kernel(support.x_frequency_size(),
00341                                         support.y_frequency_size(),
00342                                         complex_type());
00343 
00344       const real_type width  = static_cast<real_type>(support.x_space_size());
00345       const real_type height = static_cast<real_type>(support.y_space_size());
00346     
00347       const real_type small_sigma_x = 2 * width / small_wave_length;
00348       const real_type small_sigma_y = 2 * height / small_wave_length;
00349 
00350       const real_type large_sigma_x = 2 * width / large_wave_length;
00351       const real_type large_sigma_y = 2 * height / large_wave_length;
00352 
00353       gaussian_type small_gaussian(0,0,small_sigma_x,small_sigma_y,0);
00354       gaussian_type large_gaussian(0,0,large_sigma_x,large_sigma_y,0);
00355 
00356       const dog_type dog(small_gaussian,large_gaussian);
00357 
00358       // Creation of DoG kernel
00359       FFT::fill_real_part(dog,&dog_kernel);
00360 
00361       // Load the data in the FFT engine
00362       support.load_frequency_data(dog_kernel);
00363 
00364       // Multiplication "in place" in the frequency space.    
00365       support.multiply_frequency_data_by_buffer(F,false);
00366 
00367       // Return data into a buffer.
00368       support.save_frequency_data_into_buffer(*G);
00369     }
00370 
00371   }
00372   
00373 }
00374 
00375 #endif

Generated on Thu Aug 19 15:55:51 2004 by doxygen1.2.18