# How to use inverse 2D Fourier transform to reconstruct the original image?

I have managed to get the forward Fourier transform of an image to the frequency space like so:

But I cannot for the life of me reconstruct the original image from the inverse Fourier transform of this frequency image? Can someone give pointers, please?

According to various articles, we are supposed to be using somehow both the Real and Imaginary (or Magnitude and Phase) of the results for frequency, so I have saved both the original Real and Imaginary parts while doing the forward transform.

My question is, how can we use these Real and Imaginary parts to reconstruct the original image back using inverse Fourier transform?

Thank you.

• Whatever library you have used to do the forward FFT will provide an inverse FFT as well. Look that up and read the documentation. Dec 17, 2021 at 18:16
• @Hilmar thanks, i am doing it from scratch this time, pixel by pixel here we go... :)
– user60606
Dec 17, 2021 at 18:18
• It would be helpful if you edit your question with the information that you're rolling your own. Dec 17, 2021 at 19:20
• how does one do a "pixel by pixel" FFT? an FFT is always an operation of vectors; complex vector of length N in, complex vector of length N out. Dec 18, 2021 at 13:12

## 2 Answers

The inverse FFT is almost identical to the forward one, so you can use what you already have:

1. Transpose and take conjugate complex
2. Apply forward 2D FFT
3. Transpose and take conjugate complex again
4. Divide by number of elements in the matrix (e.g. 256 for an 8x8 matrix)
• @ Hilmar thanks! I am still a bit vague about what to do from here, but here's a toy example. Suppose the image is of size 4x4 as follows: [[1,2,1,2],[2,5,4,3],[6,4,3,2],[1,3,2,1]]. Could you perhaps show a simple code for calculating the complete 4x4 Fourier frequencies of these entries, then the code to reconstruct back the original numbers exactly using inverse Fourier process, please?
– user60606
Dec 17, 2021 at 18:45
• There would be way more code than information. Dec 17, 2021 at 19:20
• @James you already have the FFT code; so, instead of running $[[1,2,1,2],[\ldots$ through it, run the result throught it again (after modification as described in steps 3 and 4). You haven't explained why you can't just do that! Dec 18, 2021 at 13:14

A 2D rectangular FFT is just an FFT of all the columns then an FFT of all the rows (or visa-versa).

A 2D rectangular IFFT is just the IFFT of all the columns and then all of the rows.

If you have your FFT code all written, and it's written to accept complex data (which is usually a good idea), then if you start with $$x(n)$$ and take it's FFT, the FFT of that will be a scaled and time-reversed FFT of $$x(n)$$.

So if you just take the FFTs that you're generating and take their FFTs, you should get the same images back, only with the pixel values much higher and the letters rotated by 180 degrees.

Once you see that, then you can start working on your IFFT routines.

• @ TimWescott thank you! I have wondered some about that, using complex input. Since original image is only real-valued, do we construct as input complex numbers with all Imaginary parts zero, like [255,0],[134,0],[23,0],... ? Then, feeding it into the DFT forward transform sum over_all_pixels += [cos(a),sin(a)] where a = - 2 Pi * (u * i / Width + v * j / Height)... Where should the real and complex part be inputed into this forward fourier function? Thanks!
– user60606
Dec 17, 2021 at 19:34
• @James: Yes, $a = a + j0$, and that's exactly how you express a real $a$ as a complex number. Dec 18, 2021 at 0:20