Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleFFT2D_free.cpp

Example for using the fast fourier Transform (FFT)

Author
MIP
/* This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
/**
* @example ExampleFFT2D_free.cpp
@relates FFT2D_free
@brief Example for using the fast fourier Transform (FFT)
@ingroup g_examples
@author MIP
*/
#include <Image/FFT2D_free.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Debug/TimeMeasure.hh>
using namespace std;
using namespace BIAS;
int main(int argc, char *argv[])
{
TimeMeasure StopWatch;
Image<unsigned char> im1, im1grey,res;
if (argc<2){
im1grey.Init(160,120,1);
}
else {
if (ImageIO::Load(argv[1], im1)!=0){
BIASERR("error loading image "<<argv[1]);
return -2;
}
ImageConvert::ToGrey(im1,im1grey);
}
ImageIO::Save("FFT2D_free_Grey1",im1grey);
cout <<"Image dimensions: "<<im1grey.GetWidth()<<"x"<<im1grey.GetHeight()<<endl;
Image<float> complex,value;
// warm-up
fft.Forward(im1grey,complex);
fft.Forward(im1grey,complex);
fft.Forward(im1grey,complex);
StopWatch.Start();
// for (unsigned int i=0;i<100;i++)
fft.Forward(im1grey,complex);
StopWatch.Stop();
cout <<"FFT Forward took [ms] :"<<StopWatch.GetRealTime()/1000/100<<endl;;
ImageIO::Save("FFT2D_free_Spectrum_complex",complex);
//fft.Normalize(complex);
StopWatch.Reset();
StopWatch.Start();
fft.GetMagnitude(complex,value);
StopWatch.Stop();
cout <<"FFT GetValue took [ms] :"<<StopWatch.GetRealTime()/1000<<endl;;
ImageIO::Save("FFT2D_free_Spectrum_value",value);
//fft.Normalize(complex);
ImageIO::Save("FFT2D_free_Spectrum_normalized",complex);
fft.Reverse(complex,res);
Image<unsigned char> resRGB(im1grey.GetWidth(), im1grey.GetHeight(), 3);
ImageConvert::ToRGB(res, resRGB);
ImageIO::Save("FFT2D_free_Reverse",resRGB);
return 0;
}