I was asked to perform DFT on an image twice as a part of my school assignment. Why am I getting a blurry inverted image when I perform DFT on an image twice? Sorry, I'm new to image processing and signal processing. Can someone help me explain this mathematically?

Here's the result I obtained. PS: I used FFT algorithms to perform the DFT. (Python and numpy, np.fft.fft2) Original Image, Magnitude Spectrum of the DFT, and Magnitude Spectrum of double DFT, in order

[Edit]: I haven't shifted the DC value, F(0,0), to the center as usual, for the magnitude spectra given here. (I haven't used np.fft.fftshift)

Here's the exact code I used.

import numpy as np
from matplotlib import pyplot as plt

img = plt.imread("Q4.tif")
dft = np.fft.fft2(img)
dft_of_dft = np.fft.fft2(dft)

spectrum = np.abs(dft)
c = 255 / log(1 + np.amax(spectrum))
spectrum = c*np.log(spectrum)

double_dft_spectrum = np.abs(dft_of_dft)
c = 255 / log(1 + np.amax(double_dft_spectrum))
double_dft_spectrum = c*np.log(double_dft_spectrum)

p, axarr = plt.subplots(1, 3, figsize=(12,4))
axarr[0].imshow(img, cmap = 'gray')
axarr[0].set_title('Original Image')
axarr[1].imshow(spectrum, cmap = 'gray')
axarr[2].imshow(double_dft_spectrum, cmap = 'gray')
axarr[2].set_title('Double DFT')
  • $\begingroup$ What are you using to apply the FFT? $\endgroup$ – Royi Jan 16 '19 at 13:15
  • $\begingroup$ @Royi I'm using python and numpy. Using np.fft.fft2 function to be exact. $\endgroup$ – icyfire Jan 16 '19 at 13:18
  • $\begingroup$ Share your code and we'll assist you. I would guess you use fft twice. $\endgroup$ – Royi Jan 16 '19 at 13:23
  • $\begingroup$ @Royi I have added the code in a new edit. $\endgroup$ – icyfire Jan 16 '19 at 13:27

It's a DFT property that if you apply DFT twice to input data, you get the original signal flipped (circularly). Stated mathematically for 1D case:

$$ x[n] \xrightarrow{ N-DFT } X[k] $$ $$ X[k] \xrightarrow{ N-DFT } Y[k] = N x[-k] $$

similar result can be shown for 2D case. And as you can see, the resulting output is the flipped (horizontally and vertically) original data.

You can see mathematical derivation in other questions on this site. I remember having answered that before. Please check this site for applying DFT or FFT twice.

Such as this answer...

| improve this answer | |
  • $\begingroup$ @Royi Oh I didin't see you were waiting for his response. Anyway you can still fix his code... ;-) $\endgroup$ – Fat32 Jan 16 '19 at 13:28
  • $\begingroup$ Thank you for an answer. Could you give some link or any kind of reference to read more about this? As I mentioned I'm a beginner I'm gonna need a little bit more explanation. $\endgroup$ – icyfire Jan 16 '19 at 13:28
  • $\begingroup$ @Fat32, I was kidding. As long the information is right this is good. $\endgroup$ – Royi Jan 16 '19 at 13:29
  • $\begingroup$ @icyfire I pointed another answer for your help. $\endgroup$ – Fat32 Jan 16 '19 at 13:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.