Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleFFT2D_free.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
22 
23 
24 /**
25  * @example ExampleFFT2D_free.cpp
26  @relates FFT2D_free
27  @brief Example for using the fast fourier Transform (FFT)
28  @ingroup g_examples
29  @author MIP
30 */
31 
32 #include <Image/FFT2D_free.hh>
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Base/Debug/TimeMeasure.hh>
37 
38 using namespace std;
39 using namespace BIAS;
40 
41 
42 int main(int argc, char *argv[])
43 {
44  TimeMeasure StopWatch;
45  Image<unsigned char> im1, im1grey,res;
46 
47  if (argc<2){
48  im1grey.Init(160,120,1);
49  im1grey.FillImageWithXValue();
50  }
51  else {
52  if (ImageIO::Load(argv[1], im1)!=0){
53  BIASERR("error loading image "<<argv[1]);
54  return -2;
55  }
56  ImageConvert::ToGrey(im1,im1grey);
57  }
58 
59 
60  ImageIO::Save("FFT2D_free_Grey1",im1grey);
61  cout <<"Image dimensions: "<<im1grey.GetWidth()<<"x"<<im1grey.GetHeight()<<endl;
62 
64 
65  Image<float> complex,value;
66 
67  // warm-up
68  fft.Forward(im1grey,complex);
69  fft.Forward(im1grey,complex);
70  fft.Forward(im1grey,complex);
71 
72  StopWatch.Start();
73 // for (unsigned int i=0;i<100;i++)
74  fft.Forward(im1grey,complex);
75  StopWatch.Stop();
76  cout <<"FFT Forward took [ms] :"<<StopWatch.GetRealTime()/1000/100<<endl;;
77  ImageIO::Save("FFT2D_free_Spectrum_complex",complex);
78 
79  //fft.Normalize(complex);
80 
81  StopWatch.Reset();
82  StopWatch.Start();
83  fft.GetMagnitude(complex,value);
84  StopWatch.Stop();
85  cout <<"FFT GetValue took [ms] :"<<StopWatch.GetRealTime()/1000<<endl;;
86  ImageIO::Save("FFT2D_free_Spectrum_value",value);
87 
88  //fft.Normalize(complex);
89  ImageIO::Save("FFT2D_free_Spectrum_normalized",complex);
90 
91 
92 
93  fft.Reverse(complex,res);
94  Image<unsigned char> resRGB(im1grey.GetWidth(), im1grey.GetHeight(), 3);
95  ImageConvert::ToRGB(res, resRGB);
96  ImageIO::Save("FFT2D_free_Reverse",resRGB);
97 
98 
99  return 0;
100 }
101 
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void FillImageWithXValue()
fills image with value depending on x coordinate
Definition: Image.cpp:608
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
void GetMagnitude(const Image< float > &ComplexIn, Image< float > &value)
take the spectrum image (2-channel) and compute the absolute value for each pixel ...
Definition: FFT2D_free.cpp:197
Wrapper to the fftpack library from netlib (see fftpack/fft.c), implementing the fft (Fast Fourier Tr...
Definition: FFT2D_free.hh:42
void Reverse(const Image< float > &ComplexIn, Image< StorageType > &res)
Definition: FFT2D_free.cpp:154
void Forward(const Image< StorageType > &in, Image< float > &ComplexOut)
apply FFT on
Definition: FFT2D_free.cpp:120
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111