#include <stdio.h> #include <stdlib.h> #include <string.h> #include "FloatImage2D.h" #include "FloatKernel2D.h" #include "FourierTransform2D.h" // Example program for the "FourierTransform2D" class // // Usage: // test_fft <input_image> // int main(int argc, char *argv[]) { // Test for the correct number of arguments in the command line if (argc != 2) { cout << "Usage: " << argv[0] << " <input_image>" << endl; exit(0); } // Read an image as floating point and display it FloatImage2D im0(256,256,"res.pgm"); im0.readImage(argv[1]); im0.showImage(); // Print some image statistics cout << "Original image statistics" << endl; cout << " Min: " << im0.min() << endl; cout << " Max: " << im0.max() << endl; cout << " Avg: " << im0.avg() << endl; cout << " Std. dev.: " << im0.dev() << endl << endl; // Initialize the FourierTransform2D object with the input image FourierTransform2D a(im0); // Perform the fft a.fft(); // Display the magnitude and the phase // parameters: 1 - display log of the values // 0 - display the values as they are a.showMagnitude(1); a.showPhase(0); // Retrieve the real and the imaginary part of the Fourier transform FloatImage2D real, imag; real = a.getReal(); imag = a.getImag(); real.showImage(); // Perform the inverse Fourier transform a.ifft(); // Retrieve the real and imaginary parts obtained after // the inverse transform FloatImage2D real1, imag1; real1 = a.getReal(); imag1 = a.getImag(); // Display the result and check if the image after FFT - IFFT has the same // statistics real1.showImage(); cout << "FFT-IFFT image statistics" << endl; cout << " Min: " << real1.min() << endl; cout << " Max: " << real1.max() << endl; cout << " Avg: " << real1.avg() << endl; cout << " Std. dev.: " << real1.dev() << endl << endl; getchar(); // Close the magnitude and phase windows a.closeWindows(); // Close the other windows im0.closeWindow(); real.closeWindow(); // imag.closeWindow(); real1.closeWindow(); // imag1.closeWindow(); return(1); }