Inverse Fourier gives black figure

asked 2013-09-24 11:57:03 -0500

GiulSDU gravatar image

updated 2013-09-24 13:45:00 -0500

berak gravatar image

Hi, i try to apply the inverse of fourier Trasform to a Image Sperctrum but it does not work, i end up with a black image.

Mat Lena;

   Mat padded;                            //expand input image to optimal size
      int m = getOptimalDFTSize( Lena.rows );
      int n = getOptimalDFTSize( Lena.cols ); // on the border add zero values
      copyMakeBorder(Lena, padded, 0, m - Lena.rows, 0, n - Lena.cols, BORDER_CONSTANT, Scalar::all(0));

      Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
      Mat complexI;
      merge(planes, 2, complexI);         // Add to the expanded another plane with zeros

      dft(complexI, complexI);            // this way the result may fit in the source matrix
      Mat_<float> magI;

      split(complexI, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
      magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude



      magI(cv::Rect(magI.cols/2 - 25, magI.rows/2 -25, 50, 50)) = 250.0f;


      Mat_<float> filtered;
      //from polar to car
      //phase(planes[1], planes[0], planes[1], false);

      Mat_<Vec2f> complexI_2;
      merge(planes, 2, complexI_2);
      dft(complexI_2, filtered,  DFT_INVERSE + DFT_SCALE + DFT_REAL_OUTPUT, 0);
      normalize(filtered, filtered, 0, 1, CV_MINMAX);

      namedWindow("Filtered Im", CV_WINDOW_AUTOSIZE );
      imshow("Filtered Im", filtered );

      namedWindow("ImageHisto", CV_WINDOW_AUTOSIZE );
      imshow("ImageHisto", histo(Lena) );

      namedWindow("FilteredImage Histo", CV_WINDOW_AUTOSIZE );
      imshow("FilteredImage Histo", histo(filtered) );


Everything is working until i modify the magnitude. I get the modified spectrum (magI) end then i am suppose to compute the inverse Trasform. I think the problem could be in PolarToCar because it takes as parameter the magnitude and the phase, but i am not sure i actually have the phase, i think i have the imaginary part of the spectrum stored in planes[1]. thanks

edit retag flag offensive close merge delete