title: DFT to spatial domain in OpenCV is not working
body: <p>I have created dft of an image and after some adjustment with filters i want to convert it back to the real image but every time when i do that it gives me wrong result ..seems like its not converting it back.
  <code>ForierTransform</code> and <code>createGaussianHighPassFilter</code> are my own functions rest of the code i am using like below for the inversion back to real image.</p>
  
  <pre><code>Mat fft = ForierTransform(HeightPadded,WidthPadded);
  Mat ghpf = createGaussianHighPassFilter(Size(WidthPadded, HeightPadded), db);
  Mat res;
  cv::multiply(fft,ghpf,res);
  imshow("fftXhighpass1", res);
  idft(res,res,DFT_INVERSE,res.rows);
  cv::Mat croped = res(cv::Rect(0, 0, img.cols,img.rows));
  
  //res.convertTo(res,CV_32S);
  imshow("fftXhighpass", res);
  </code></pre>
  
  <p>even if i dont apply the filter  i am unable to reverse back dft result ...
  here is my dft code is , i could not find any sample to reverse dft back to normal image..</p>
  
  <pre><code>Mat ForierTransform(int M,int N)
  {
      Mat img = imread("thumb1-small-test.jpg", CV_LOAD_IMAGE_GRAYSCALE);
      Mat padded;
      copyMakeBorder(img, padded, 0, M - img.rows, 0, N - img.cols, BORDER_CONSTANT, Scalar::all(0));
  
      Mat planes[] = {Mat_&lt;float&gt;(padded), Mat::zeros(padded.size(), CV_32F)};
      Mat complexImg;
      merge(planes, 2, complexImg);
  
      dft(complexImg, complexImg);
  
  
      split(complexImg, planes);
      magnitude(planes[0], planes[1], planes[0]);
      Mat mag = planes[0];
      mag += Scalar::all(1);
      log(mag, mag);
  
          // crop the spectrum, if it has an odd number of rows or columns
      mag = mag(Rect(0, 0, mag.cols &amp; -2, mag.rows &amp; -2));
  
  
      normalize(mag, mag, 0, 1, CV_MINMAX);
      return mag;
  }
  </code></pre>
  
  <p>kindly help</p>
  
  <p>[EDIT: After I found the solution with the help of mevatron] (below is the correct code)</p>
  
  <pre><code> Mat ForierTransform(int M,int N)
  {
      Mat img = imread("thumb1-small-test.jpg", CV_LOAD_IMAGE_GRAYSCALE);
      Mat padded;
      copyMakeBorder(img, padded, 0, M - img.rows, 0, N - img.cols, BORDER_CONSTANT, Scalar::all(0));
  
      Mat planes[] = {Mat_&lt;float&gt;(padded), Mat::zeros(padded.size(), CV_32F)};
      Mat complexImg;
      merge(planes, 2, complexImg);
  
      dft(complexImg, complexImg);
  
      return complexImg;
  }
  
  Mat img = imread("thumb1-small-test.jpg",CV_LOAD_IMAGE_GRAYSCALE);
  int WidthPadded=0,HeightPadded=0;
  WidthPadded=img.cols*2;
  HeightPadded=img.rows*2;
  int M = getOptimalDFTSize( img.rows );
  //Create a Gaussian Highpass filter 5% the height of the Fourier transform
  double db  = 0.05 * HeightPadded;
  
  
  Mat fft = ForierTransform(HeightPadded,WidthPadded);
  Mat ghpf = createGaussianHighPassFilter(Size(WidthPadded, HeightPadded), db);
  Mat res;
  
  cv::mulSpectrums(fft,ghpf,res,DFT_COMPLEX_OUTPUT);
  
  
  idft(res,res,DFT_COMPLEX_OUTPUT,img.rows);
  
  Mat padded;
  copyMakeBorder(img, padded, 0, img.rows, 0, img.cols, BORDER_CONSTANT, Scalar::all(0));
  Mat planes[] = {Mat_&lt;float&gt;(padded), Mat::zeros(padded.size(), CV_32F)};
  split(res, planes);
  magnitude(planes[0], planes[1], planes[0]);
  Mat mag = planes[0];
  mag += Scalar::all(1);
  log(mag, mag);
  
  // crop the spectrum, if it has an odd number of rows or columns
  mag = mag(Rect(0, 0, mag.cols &amp; -2, mag.rows &amp; -2));
  
  int cx = mag.cols/2;
  int cy = mag.rows/2;
  
  normalize(mag, mag, 1, 0, CV_MINMAX);
  
  cv::Mat croped = mag(cv::Rect(cx, cy, img.cols,img.rows));
  cv::threshold(croped , croped , 0.56, 1, cv::THRESH_BINARY);
  
  imshow("fftPLUShpf", mag);
  imshow("cropedBinary", croped);
  </code></pre>
  
  <p>It now can able to display ridges valley of finger , and can be more optimize with respect to threshold as well</p>