python傅里叶逆变换_使用一维变换实现二维逆傅里叶变换

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:

def IDFT2(fourier_image):

image = np.zeros(fourier_image.shape)

for col in range(image.shape[1]):

image[:, col] = IDFT1(fourier_image[:, col])

for row in range(image.shape[0]):

image[row, :] = IDFT1(image[row,:])

return image

What did I do wrong? I am pretty sure that IDFT1 works fine, and so is the regular 2D-DFT.

解决方案

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:

DFT rows from real to complex domain

DFT columns of result from complex to complex domain

apply normalization if needed

any or none processing ...

iDFT rows from complex to complex domain

iDFT columns of result from complex to real domain

apply normalization if needed

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值