1

I am trying implement inverse discrete Fourier transfrom for the image which i applied discrete Fourier transform beforehand. The output is kind of two images. One image is in correct position the other is reversed position. Could you help me to solve this issue?

Here is the code i have written.

double inverseFourierReal = 0.0;
    double inverseFourierImg = 0.0;
    double degreeValue,cosValue,sinValue;
   // double inverse = inverseFourier;
    for(int rowm = 0; rowm < rows; rowm++ )
    for(int coln = 0; coln < cols; coln++ ) {


        inverseFourierImg = 0.0;
        inverseFourierReal = 0.0;
        for(int rowk = 0; rowk < rows; rowk++ ) {
           for(int coll = 0; coll < cols; coll++ ) {



           degreeValue  = 2. * PI * (float(rowk*rowm)/rows + float(coll*coln)/cols);
           cosValue  = cos(degreeValue);
           sinValue  = sin(degreeValue);

           inverseFourierReal += cosValue * fourierImageReal[rowk][coll] - sinValue * fourierImageImg[rowk][coll];
           //inverseFourierImg += (cosValue * fourierImageImg[rowk][coll] + sinValue * fourierImageReal[rowk][coll]);
           //cout<<inverseFourierReal;

            }

       }

        invr_FourierReal.at<double>(rowm,coln) = abs((inverseFourierReal) / (sqrt(rows*cols)));
       // invr_FourierReal.at<double>(rowm,coln) = double(inverseFourierReal) / (sqrt(rows*cols));
        //invr_FourierImg.at<double>(int(rowm),int(coln)) = double(inverseFourierImg) / (sqrt(rows*cols));


    }

You can see the output image here:

img

Edit: I have changed the code and you can see new output. it is upside down. imgg I used Lena image for the input
P.S sorry for my poor English.

Hikmat
  • 57
  • 9
  • how can we help when we do not see the part of code you are doing this with? most likely similar problem to this: [Implementing 2D inverse fourier transform using 1D transforms](http://stackoverflow.com/a/40816757/2521214) – Spektre Dec 05 '16 at 08:44
  • @Spektre Thanks for your respond. I have added the piece of code which i used for inverse transformation – Hikmat Dec 05 '16 at 08:58
  • Added answer at least that is how I see it. – Spektre Dec 05 '16 at 09:17
  • I have corrected my mistake. Could you please look to the new output – Hikmat Dec 05 '16 at 09:18

1 Answers1

0

Weird mirrored blend

What is fourierFilterImg? are you doing some kind of convolution instead of IDFT? Also hope invr_FourierReal is not the same memory place as fourierImageReal. My bet is that it is just a copy/paste typo so I would change this line:

inverseFourierReal += (cosValue * fourierImageReal[rowk][coll] - sinValue * fourierFilterImg[rowk][coll]);

To:

inverseFourierReal += cosValue * fourierImageReal[rowk][coll] - sinValue * fourierImageImg[rowk][coll];

Also I hope your input image is correctly DFT transformed and in complex domain.

[Edit1] inversion of X,Y

That can be just not the same counting of row,col direction for DFT and IDFT somewhere. Images usually have Y axis going down and X axis going right. If it is just upside down then just invert the one that is wrong.

If the problem is in IDFT then just change:

invr_FourierReal.at<double>(rowm,coln)

to:

invr_FourierReal.at<double>(rows-rowm-1,cols-coln-1)

But my bet is that it is just inverted during loading or rendering and DFT/IDFT has nothing to do with this.

Spektre
  • 49,595
  • 11
  • 110
  • 380