Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

test_fft_mod.cpp

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include "FloatImage2D.h"
00005 #include "FloatKernel2D.h"
00006 #include "FourierTransform2D.h"
00007 
00008 //   Example program for the "FourierTransform2D" class
00009 //
00010 //   Usage:
00011 //      test_fft <input_image>
00012 //
00013 
00014 int main(int argc, char *argv[])
00015 {
00016   // Test for the correct number of arguments in the command line
00017   if (argc != 2) {
00018     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00019     exit(0);
00020   }
00021 
00022   // Read an image as floating point and display it
00023   FloatImage2D im0(256,256,"res.pgm");
00024   im0.readImage(argv[1]);
00025   im0.showImage();
00026 
00027   // Print some image statistics
00028   cout << "Original image statistics"  << endl;
00029   cout << " Min:       " << im0.min() << endl;
00030   cout << " Max:       " << im0.max() << endl;
00031   cout << " Avg:       " << im0.avg() << endl;
00032   cout << " Std. dev.: " << im0.dev() << endl << endl;
00033 
00034   // Initialize the FourierTransform2D object with the input image
00035   FourierTransform2D a(im0);
00036 
00037   // Perform the fft
00038   a.fft();
00039 
00040   // Display the magnitude and the phase
00041   // parameters: 1 - display log of the values 
00042   //             0 - display the values as they are
00043   a.showMagnitude(1);
00044   a.showPhase(0);
00045 
00046   // Retrieve the real and the imaginary part of the Fourier transform
00047   FloatImage2D real, imag;
00048   real = a.getReal();
00049   imag = a.getImag();
00050   real.showImage();
00051 
00052   // Perform the inverse Fourier transform
00053   a.ifft();
00054 
00055   // Retrieve the real and imaginary parts obtained after
00056   // the inverse transform
00057   FloatImage2D real1, imag1;
00058   real1 = a.getReal();
00059   imag1 = a.getImag();
00060 
00061   // Display the result and check if the image after FFT - IFFT has the same
00062   // statistics
00063   real1.showImage();
00064   cout << "FFT-IFFT image statistics"  << endl;
00065   cout << " Min:       " << real1.min() << endl;
00066   cout << " Max:       " << real1.max() << endl;
00067   cout << " Avg:       " << real1.avg() << endl;
00068   cout << " Std. dev.: " << real1.dev() << endl << endl;
00069 
00070   getchar();
00071   
00072   // Close the magnitude and phase windows
00073   a.closeWindows();
00074 
00075   // Close the other windows
00076   im0.closeWindow();
00077   real.closeWindow();
00078 //    imag.closeWindow();        
00079   real1.closeWindow();
00080 //    imag1.closeWindow();        
00081 
00082   return(1);
00083 }
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094