I am trying to implement in python some functions that transform images to their fourier domain and vice-versa for image processing tasks.
I implemented the 2D-DFT using repeated 1D-DFT, and it worked fine, but when I tried to Implement 2D inverse DFT using repeated inverse 1D-DFT, some weird problem occurred - When I transform an image to its fourier domain and then back to the image domain, it looks like the image was reflected and merged with its reflection, as can be seen here:
this is the input:
and this is the output
This is the function that is responsible for the mess:
image = np.zeros(fourier_image.shape)
for col in range(image.shape):
image[:, col] = IDFT1(fourier_image[:, col])
for row in range(image.shape):
image[row, :] = IDFT1(image[row,:])
w = np.exp(-(1/N) * 2 * np.pi * 1j)
DFT_matrix = np.array([range(N)] * N)
DFT_matrix = (DFT_matrix.T.dot(DFT_matrix) / N).astype(np.int64)
DFT_matrix = w ** DFT_matrix
DFT_matrix = create_DFT_matrix(fourier_signal.shape)
IDFT_matrix = np.linalg.inv(DFT_matrix)
signal = matrix.dot(fourier_signal.T)
I do not use Python so I am not confident to analyze your code but my bet is that you most likely forget to implement complex values at some stage....
it should be:
if you use just real to complex domain DFT/iDFT in the second passes (bullets #2,#6) then it would create the mirroring because DFT of real values is a mirrored sequence ... Btw. it does not matter if you process rows or columns first ... also you can process rows first in DFT and columns first in iDFT the result should be the same +/- floating errors ...
for more info see
and all the sub-links there especially the
2D FFT and wrapping example so you can compare your results with something working