#include "libfft.h"
#include "utils.h"

using namespace std;
using namespace fft;

int main(int argc, char** argv)
{
   Config cfg(argv[1]);
   
   String imgFileName;
   fft::real loPass;
   cfg["src_image"].to(imgFileName);
   cfg["lo_pass"].to(loPass);




   Array2D<Complex> img = Array2D<Complex>(imread(imgFileName));
   Array2D<Complex> fimg = img;
   fft2(fimg);
   fftshift2(fimg);

   Array2D<fft::real> rfimg = fft::abs(fimg);
   rfimg.logNormalize();
   imsave(rfimg, imgFileName + "-spectra.png");


   Array2D<Complex> mask(img.W(), img.H());
   mask.circle(img.W() * .5 * loPass, 1, 0);



   fimg = fimg * mask;

   ifftshift2(fimg);
   ifft2(fimg);

   //fimg.flipV();

   imsave(fft::abs(fimg), imgFileName + "-blur.png");
   img = img - fft::abs(fimg);

   Array2D<fft::real> simg = fft::abs(img);
   simg.normalize();
   //simg.storeGnuPlot("simg.dat", 16, 16);
   imsave(simg, imgFileName + "-out.png");
   

   return 0;
}
