MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab与Numpy + Python FFT2之间有差异吗? (https://www.labfans.com/bbs/showthread.php?t=26704)

poster 2019-12-14 20:46

Matlab与Numpy + Python FFT2之间有差异吗?
 
所以我在Numpy上做一些关于Python绕射的作业。我的结果根本无法证明结果应该如何,我感到困惑。

我用来生成FFT的代码如下:

Python: aperaturearray = np.array(im) # Turn image into numpy array Ta = np.fft.fftshift(np.fft.fft2(aperaturearray)) ### I did some calculations here ### ftfm = Image.fromarray(np.uint8(Utfm)) ftfm.save(("Path")) Matlab: rect = imread('PATH\pyRectangle.jpg'); rectfft = fft2(rect); imwrite(rectfft, 'C:\Users\Dan\Documents\python\DiffPhotos\matlabRectfft','jpg') pyrectmat = ifft2(pyfftrect); imwrite(pyrectmat, 'Path','jpg') 图像在这里-> [URL]http://imgur.com/a/3Cw81#EdFoA[/URL]

现在这是怎么回事?为什么FFT图像如此不同?不同的实现?为什么我的作业代码不起作用:(



[B]回答:[/B]

首先,在Matlab中,从fft2返回的值很复杂。我不确定书写会如何处理它们。尝试使用此代码似乎可以得出明智的结果。 (使用log10有助于显示)

rect = imread('rect.jpg'); rectfft = fft2(rect); pcolor(log10(abs(rectfft))); shading flat 由于像素索引可能与图像的空间频率有关,因此图像在原点周围偏移。即低空间频率似乎接近0,0。较高的像素标记是这些频率的别名。您可以通过一些矩阵操作重新排列图像以将(0,0)放在中间。



[url=https://stackoverflow.com/questions/5415113]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:16

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.