Image Component Library (ICL)
FFTUtils.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLMath/src/ICLMath/FFTUtils.h **
10 ** Module : ICLMath **
11 ** Authors: Christian Groszewski, Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/BasicTypes.h>
35 #include <ICLMath/DynMatrix.h>
36 #include <ICLMath/FFTException.h>
37 #include <string.h>
38 #include <complex>
39 
40 using namespace icl::utils;
41 
42 namespace icl{
43  namespace math{
44 
45  namespace fft{
46 
48  static const double FFT_2_PI = 2.0*3.1415926535897932384626433832795288419716939937510;
49 
51  static const double FFT_PI = 3.1415926535897932384626433832795288419716939937510;
52 
54  static const double FFT_PI_HALF = 1.5707963267948966192313216916397644209858469968755;
55 
57 
67  template<typename T1,typename T2> ICLMath_IMP
68  std::complex<T2>* fft(unsigned int n, const T1* data);
69 
71 
81  template<typename T1, typename T2> ICLMath_IMP
83  DynMatrix<std::complex<T2> > &dst,DynMatrix<std::complex<T2> > &buf);
84 
86 
96  template<typename T1, typename T2> ICLMath_IMP
97  DynMatrix<std::complex<T2> >& fft2D(const DynMatrix<T1> &src, DynMatrix<std::complex<T2> > &dst,
98  DynMatrix<std::complex<T2> > &buf);
99 
101 
109  template<typename T1, typename T2> ICLMath_IMP
110  std::complex<T2>* dft(unsigned int n, T1 *matrix);
111 
113 
122  template<typename T1, typename T2> ICLMath_IMP
124  DynMatrix<std::complex<T2> >& dst,DynMatrix<std::complex<T2> >&buf);
125 
127 
134  template<typename T1, typename T2> ICLMath_IMP
135  std::complex<T2>* ifft_cpp(unsigned int n, const T1* matrix);
136 
138 
146  template<typename T1, typename T2> ICLMath_IMP
148  DynMatrix<std::complex<T2> > &dst,DynMatrix<std::complex<T2> > &buf);
149 
151 
160  template<typename T1, typename T2> ICLMath_IMP
161  DynMatrix<std::complex<T2> >& ifft2D(const DynMatrix<T1> &src, DynMatrix<std::complex<T2> > &dst,
162  DynMatrix<std::complex<T2> > &buf);
163 
165 
170  template<typename T1, typename T2> ICLMath_IMP
171  std::complex<T2>* idft(unsigned int n, T1 *matrix);
172 
174 
181  template<typename T1, typename T2> ICLMath_IMP
182  DynMatrix<std::complex<T2> > &idft2D(DynMatrix<T1> &src, DynMatrix<std::complex<T2> > &dst,
183  DynMatrix<std::complex<T2> > &buf);
184 
186 
191  template<typename T> ICLMath_IMP
193 
195 
200  template<typename T> ICLMath_IMP
202 
204 
209  template<typename T> ICLMath_IMP
210  DynMatrix<T>& powerspectrum(const DynMatrix<std::complex<T> > &src, DynMatrix<T> &dst);
211 
213 
218  template<typename T> ICLMath_IMP
219  DynMatrix<T>& logpowerspectrum(const DynMatrix<std::complex<T> > &src, DynMatrix<T> &dst);
220 
222 
229  template<typename T> ICLMath_IMP
230  DynMatrix<T> &makeborder(const DynMatrix<T> &src, DynMatrix<T> &dst, T borderFill);
231 
233 
239  template<typename T> ICLMath_IMP
241 
243 
250  template<typename T> ICLMath_IMP
252 
253 
255  ICLMath_API int nextPowerOf2(int n);
256 
258  ICLMath_API int priorPowerOf2(int n);
259 
261 
267  template<typename T> ICLMath_IMP
268  void split_complex(const DynMatrix<std::complex<T> > &src, DynMatrix<T> &real, DynMatrix<T> &img);
269 
271 
276  template<typename T1, typename T2> ICLMath_IMP
277  DynMatrix<T2> &imagpart(const DynMatrix<std::complex<T1> > &src, DynMatrix<T2> &dst);
278 
280 
285  template<typename T1, typename T2> ICLMath_IMP
286  DynMatrix<T2> &realpart(const DynMatrix<std::complex<T1> > &src, DynMatrix<T2> &dst);
287 
289 
294  template<typename T1, typename T2> ICLMath_IMP
295  DynMatrix<T2>& magnitude(const DynMatrix<std::complex<T1> > &src, DynMatrix<T2> &dst);
296 
298 
303  template<typename T1, typename T2> ICLMath_IMP
304  DynMatrix<T2>& phase(const DynMatrix<std::complex<T1> > &src, DynMatrix<T2> &dst);
305 
307 
312  template<typename T> ICLMath_IMP
313  void split_magnitude_phase(const DynMatrix<std::complex<T> > &src, DynMatrix<T> &mag, DynMatrix<T> &phase);
314 
316 
320  template<typename T1, typename T2> ICLMath_IMP
321  DynMatrix<std::complex<T2> > &joinComplex(const DynMatrix<T1> &real, const DynMatrix<T1> &im, DynMatrix<std::complex<T2> > &dst);
322 
323  } // namespace math
324 }
325 }
Definition: Any.h:38
ICLMath_IMP DynMatrix< std::complex< T2 > > & joinComplex(const DynMatrix< T1 > &real, const DynMatrix< T1 > &im, DynMatrix< std::complex< T2 > > &dst)
joins to matrices to one complex
undocument this line if you encounter any issues!
Definition: Any.h:37
ICLMath_IMP DynMatrix< T2 > & imagpart(const DynMatrix< std::complex< T1 > > &src, DynMatrix< T2 > &dst)
returns imaginary part complex matrix
#define ICLMath_API
Definition: CompatMacros.h:173
ICLMath_IMP DynMatrix< T2 > & magnitude(const DynMatrix< std::complex< T1 > > &src, DynMatrix< T2 > &dst)
returns the magnitude of complex matrix
ICLMath_IMP std::complex< T2 > * dft(unsigned int n, T1 *matrix)
1d dft computation
ICLMath_IMP DynMatrix< T > & continueMatrixToPowerOf2(const DynMatrix< T > &src, DynMatrix< T > &dst)
appends copies of sourcematrix beside and under it
Highly flexible and optimized matrix class implementation.
Definition: DynMatrix.h:81
ICLMath_IMP DynMatrix< T2 > & phase(const DynMatrix< std::complex< T1 > > &src, DynMatrix< T2 > &dst)
return phase of complexmatrix
ICLMath_IMP DynMatrix< std::complex< T2 > > & dft2D(DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2d dft computation
ICLMath_IMP DynMatrix< std::complex< T2 > > & fft2D_cpp(const DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2dfft computation (fallback)
ICLMath_IMP std::complex< T2 > * idft(unsigned int n, T1 *matrix)
1d idft computation
ICLMath_IMP DynMatrix< std::complex< T2 > > & ifft2D_cpp(const DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2d ifft computation (fallback)
ICLMath_IMP std::complex< T2 > * fft(unsigned int n, const T1 *data)
1dfft computation (fallback)
ICLMath_API int nextPowerOf2(int n)
Returns the next value greater then n to power of 2.
static const double FFT_2_PI
2*PI
Definition: FFTUtils.h:48
static const double FFT_PI_HALF
PI/2.
Definition: FFTUtils.h:54
ICLMath_IMP DynMatrix< std::complex< T2 > > & idft2D(DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2d idft computation
ICLMath_IMP DynMatrix< std::complex< T2 > > & fft2D(const DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2dfft computation
ICLMath_IMP void split_magnitude_phase(const DynMatrix< std::complex< T > > &src, DynMatrix< T > &mag, DynMatrix< T > &phase)
splits complexmatrix into magnitude and phase
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
ICLMath_IMP DynMatrix< T > & makeborder(const DynMatrix< T > &src, DynMatrix< T > &dst, T borderFill)
creates border with given value
ICLMath_IMP DynMatrix< T > & ifftshift(DynMatrix< T > &src, DynMatrix< T > &dst)
invers function to fftshift.
ICLMath_IMP DynMatrix< std::complex< T2 > > & ifft2D(const DynMatrix< T1 > &src, DynMatrix< std::complex< T2 > > &dst, DynMatrix< std::complex< T2 > > &buf)
2d ifft computation
ICLMath_IMP DynMatrix< T > & powerspectrum(const DynMatrix< std::complex< T > > &src, DynMatrix< T > &dst)
computes the powerspectrum
#define ICLMath_IMP
Definition: CompatMacros.h:172
ICLMath_IMP DynMatrix< T > & logpowerspectrum(const DynMatrix< std::complex< T > > &src, DynMatrix< T > &dst)
computes the logpowerspectrum
ICLMath_IMP DynMatrix< T2 > & realpart(const DynMatrix< std::complex< T1 > > &src, DynMatrix< T2 > &dst)
returns real part of complex matrix
ICLMath_IMP DynMatrix< T > & fftshift(DynMatrix< T > &src, DynMatrix< T > &dst)
shifts upper left corner to center.
static const double FFT_PI
PI.
Definition: FFTUtils.h:51
ICLMath_IMP void split_complex(const DynMatrix< std::complex< T > > &src, DynMatrix< T > &real, DynMatrix< T > &img)
split complexmatrix into realmatrix and imaginarymatrix
ICLMath_IMP std::complex< T2 > * ifft_cpp(unsigned int n, const T1 *matrix)
1d ifft computation
ICLMath_IMP DynMatrix< T > & mirrorOnCenter(const DynMatrix< T > &src, DynMatrix< T > &dst)
mirrors the sourcematrix
ICLMath_API int priorPowerOf2(int n)
Returns the prior value lower then n to power of 2.