boost::multi_array
.
More...Classes | |
struct | mimas::fft_t< Real, Dim, TPtr > |
Discrete fourier transform using fftw. More... | |
struct | mimas::invfft_t< Real, Dim, TPtr > |
Inverse discrete fourier transform using fftw. More... | |
struct | mimas::rfft_t< Real, Dim, TPtr > |
Discrete fourier transform of real values using fftw. More... | |
struct | mimas::invrfft_t< Real, Dim, TPtr > |
Inverse discrete fourier transform of symmetric complex array using fftw. More... | |
Functions | |
template<typename Real, std::size_t Dim, typename TPtr> | |
boost::multi_array< std::complex< Real >, Dim > | mimas::fft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field) |
Discrete fourier transform of boost::multi_array. | |
template<typename Real, std::size_t Dim, typename TPtr> | |
boost::multi_array< std::complex< Real >, Dim > | mimas::invfft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field) |
Inverse discrete fourier transform of boost::multi_array. | |
template<typename Real, std::size_t Dim, typename TPtr> | |
boost::multi_array< std::complex< Real >, Dim > | mimas::rfft (const boost::const_multi_array_ref< Real, Dim, TPtr > &field) |
Discrete fourier transform of real-valued boost::multi_array. | |
template<typename Real, std::size_t Dim, typename TPtr> | |
boost::multi_array< Real, Dim > | mimas::invrfft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field) |
Inverse discrete fourier resulting in real-valued boost::multi_array. |
boost::multi_array
.
There are several types of fourier-transforms. The current implementation only allows fourier-transforms on double precision numbers.
fft
is the complex-to-complex fourier transform. invfft
is the inverse complex-to-complex fourier transform. rfft
is the real-to-complex fourier transform (last dimension of input-array must be even). invrfft
is the inverse real-to-complex fourier transform.
// Sample application of fourier library functions // Bala Amavasai (bpa@amavasai.org) // Thu Oct 18 12:38:26 BST 2001 // Jan Wedekind (jan at wedesoft.de) // Mon Aug 23 14:37:05 UTC 2004 #include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <fstream> #include "fourier.h" #include "image.h" #include "image_fileinput.h" #include "image_funcs.h" #include "image_mesaoutput.h" #include "multi_array_op.h" using namespace boost; using namespace std; using namespace mimas; template< typename T, template< typename > class C > struct _creal: public unary_function< C< T >, T > { T operator()( const C< T > &x ) const { return x.real(); } }; template < typename T, size_t NumDims, template< class, size_t > class MultiArray, template< typename > class C > boost::multi_array< T, NumDims > creal ( const MultiArray< C< T >, NumDims > &a ) { return multi_func< T >( a, _creal< T, C >() ); }; int main(int argc, char **argv) { int retVal = 0; try { x11_display display; image< int > img; image_mesaoutput< unsigned char > window1( &display ), window2( &display ), window3( &display ), window4( &display ); ifstream file( "../images/stills/jellybeans-256x256.pgm", ios::binary ); file >> img; const_multi_array_ref< int, 2 > data ( img.rawData(), extents[ img.getHeight() ][ img.getWidth() ] ); { // Real fourier transform. multi_array< std::complex< double >,2 > imageFFT ( rfft( multi_cast< double >( data ) ) ); multi_array< double, 2 > imageLogFFT ( logarithm( norm< double >( imageFFT ) + 1.0 ) ); // Remove peak caused by constant component of input image. imageLogFFT[ 0 ][ 0 ] = 0.0; // Display. const_image_ref< double > result( imageLogFFT.data(), imageLogFFT.shape()[1], imageLogFFT.shape()[0] ); window1 << normalise( result, 0.0, 255.0 ); // Inverse fourier transform. boost::multi_array< double, 2 > result2( invrfft( imageFFT ) ); window2 << const_image_ref< double >( result2.data(), result2.shape()[1], result2.shape()[0] ); }; { // Fourier transform. multi_array< std::complex< double >,2 > imageFFT ( fft( multi_cast< std::complex< double > >( data ) ) ); multi_array< double, 2 > imageLogFFT ( logarithm( norm< double >( imageFFT ) + 1.0 ) ); // Remove peak caused by constant component of input image. imageLogFFT[ 0 ][ 0 ] = 0.0; // Display. const_image_ref< double > result( imageLogFFT.data(), imageLogFFT.shape()[1], imageLogFFT.shape()[0] ); window3 << normalise( result, 0.0, 255.0 ); // Inverse fourier transform. boost::multi_array< double, 2 > result2 ( creal( invfft( imageFFT ) ) ); window4 << const_image_ref< double >( result2.data(), result2.shape()[1], result2.shape()[0] ) << mimas::pause(); }; } catch ( exception &e ) { cerr << e.what() << endl; retVal = 1; }; return retVal; }
Have a look at the fftw info-pages. Also see fftw docs and TiP-0.0.1.
boost::multi_array< std::complex< Real >, Dim > mimas::fft | ( | const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > & | field | ) |
boost::multi_array< std::complex< Real >, Dim > mimas::invfft | ( | const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > & | field | ) |
boost::multi_array< Real, Dim > mimas::invrfft | ( | const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > & | field | ) |
boost::multi_array< std::complex< Real >, Dim > mimas::rfft | ( | const boost::const_multi_array_ref< Real, Dim, TPtr > & | field | ) |