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

test_fft2.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 "fft" and "ifft" stand-alone functions.
00009 //   For more functionality we refer to the FourierTransform class.
00010 //
00011 //   Usage:
00012 //      test_fft2 <input_image>
00013 //
00014 
00015 int main(int argc, char *argv[])
00016 {
00017   // Test for the correct number of arguments in the command line.
00018   if (argc != 2) {
00019     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00020     exit(0);
00021   }
00022 
00023   // Read an image from the file specified by "argv[1]" and display it.
00024   // Store the pixel values as floats.      
00025   FloatImage im0;
00026   im0.readImage(argv[1]);
00027   im0.showImage();
00028 
00029   // Print some image statistics.
00030   cout << "Original image statistics"  << endl;
00031   cout << " Min:       " << im0.min() << endl;
00032   cout << " Max:       " << im0.max() << endl;
00033   cout << " Avg:       " << im0.avg() << endl;
00034   cout << " Std. dev.: " << im0.dev() << endl << endl;
00035 
00036   // Perform the Fourier Transform; the real part and the imaginary
00037   // part of the result is stored in "fourier_real" and
00038   // "fourier_imag", respectively.
00039   FloatImage fourier_real, fourier_imag;
00040   fft(im0, fourier_real, fourier_imag);
00041 
00042   // Perform the inverse Fourier transform; the real part of the
00043   // is stored in "result".
00044   FloatImage result;
00045   ifft(fourier_real, fourier_imag, result);
00046   result.showImage();
00047 
00048   // Print statistics of the resulted image.
00049   cout << "FFT/IFFT image statistics"  << endl;
00050   cout << " Min:       " << result.min() << endl;
00051   cout << " Max:       " << result.max() << endl;
00052   cout << " Avg:       " << result.avg() << endl;
00053   cout << " Std. dev.: " << result.dev() << endl << endl;
00054 
00055   char l;
00056   cin >> l;  
00057   // Close the windows.
00058   result.closeWindow();
00059   im0.closeWindow();  
00060   return(1);
00061 }