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

test_fft2.cpp

/* Copyright (c) 2001 C. Grigorescu */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tip.h>

//   Example program for the "fft" and "ifft" stand-alone functions.
//   For more functionality we refer to the FourierTransform class.
//
//   Usage:
//      test_fft2 <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 from the file specified by "argv[1]" and display it.
  // Store the pixel values as floats.      
  FloatImage im0;
  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;

  // Perform the Fourier Transform; the real part and the imaginary
  // part of the result is stored in "fourier_real" and
  // "fourier_imag", respectively.
  FloatImage fourier_real, fourier_imag;
  fft(im0, fourier_real, fourier_imag);

  // Perform the inverse Fourier transform; the real part of the
  // is stored in "result".
  FloatImage result;
  ifft(fourier_real, fourier_imag, result);
  result.showImage();

  // Print statistics of the resulted image.
  cout << "FFT/IFFT image statistics"  << endl;
  cout << " Min:       " << result.min() << endl;
  cout << " Max:       " << result.max() << endl;
  cout << " Avg:       " << result.avg() << endl;
  cout << " Std. dev.: " << result.dev() << endl << endl;

  char l;
  cin >> l;  
  // Close the windows.
  result.closeWindow();
  im0.closeWindow();  
  return(1);
}