简体   繁体   English

计算 Python 中图像的 fft2

[英]Computing fft2 of an image in Python

go_dark.jpeg 转化的结果

I am experimenting with Fourier transformations and the built-in NumPy.fft library.我正在试验傅立叶变换和内置的 NumPy.fft 库。 I was trying to see the difference between computing just fft2 of an image and fftshift on fft2 of an image.我试图查看仅计算图像的 fft2 和图像的 fft2 上的 fftshift 之间的区别。 But for some reason, I am not getting the results that I was expecting.但由于某种原因,我没有得到我期望的结果。 I have tried changing images as well but regardless of what I use, I get the same results as below.我也尝试过更改图像,但无论我使用什么,我都会得到与下面相同的结果。 If someone could help me out here, it would be awesome.如果有人可以在这里帮助我,那就太棒了。 This is the code I used:这是我使用的代码:

import numpy as np
import cv2
import matplotlib.pyplot as plt
from scipy import ndimage, fftpack

light = cv2.imread("go_light.jpeg")
dark = cv2.imread("go_dark.jpeg")

g_img = cv2.cvtColor(dark, cv2.COLOR_BGR2GRAY)
di = (np.abs((np.fft.fft2(g_img))))
dm = np.abs(np.fft.fftshift(np.fft.fft2(g_img)))


plt.figure(figsize=(6.4*5, 4.8*5), constrained_layout=False)
plt.subplot(151), plt.imshow(di, "gray"), plt.title("fft");
plt.subplot(152), plt.imshow(dm, "gray"), plt.title("fftshift");
plt.show()

di and dm are floating point values. didm是浮点值。 Matplotlib can't do that. Matplotlib 不能那样做。 First, try di.astype(np.int8) .首先,尝试di.astype(np.int8) However, many of the values are out of range.但是,许多值超出了范围。 You may need to scale the array.您可能需要缩放阵列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM