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

test_fft.cpp

00001 /* Copyright (c) 2001 C. Grigorescu */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <tip.h>
00007 
00008 //   Example program for the "FourierTransform" 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 from the file specified by "argv[1]" and display it.
00023   FloatImage im0;
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 FourierTransform object with the input image.
00035   // The real part is initialized with the image, the imaginary part is 0.
00036   FourierTransform a(im0);
00037 
00038   // Perform the Fast Fourier Transform (FFT).
00039   a.fft();
00040 
00041   // Display the magnitude and the phase.
00042   // parameters: 1 - display log of the values 
00043   //             0 - display the values as they are
00044   a.showMagnitude(1);
00045   a.showPhase(0);
00046 
00047   // The real and the imaginary parts of the Fourier transform can be retrieved
00048   // with "getReal()" and "getImag()" member functions.
00049   FloatImage real, imag;
00050   real = a.getReal();
00051   imag = a.getImag();
00052 
00053   // Perform the inverse Fast Fourier Transform.
00054   a.ifft();
00055 
00056   // The real and the imaginary parts can be obtained with "getReal()" and "getImag()" 
00057   FloatImage real1, imag1;
00058   real1 = a.getReal();
00059   imag1 = a.getImag();
00060 
00061   // Display the result and statistics of the resulted image.
00062   real1.showImage();
00063   cout << "FFT-IFFT image statistics"  << endl;
00064   cout << " Min:       " << real1.min() << endl;
00065   cout << " Max:       " << real1.max() << endl;
00066   cout << " Avg:       " << real1.avg() << endl;
00067   cout << " Std. dev.: " << real1.dev() << endl << endl;
00068 
00069   char l;
00070   cin >> l;  
00071   // Close the magnitude and phase windows.
00072   a.closeWindows();
00073   // Close the other windows.
00074   im0.closeWindow();
00075   real.closeWindow();
00076   imag.closeWindow();        
00077   real1.closeWindow();
00078   imag1.closeWindow();        
00079   return(1);
00080 }