python实现二维傅里叶变换代码
时间: 2023-11-10 15:06:46 浏览: 126
傅里叶变换程序代码
3星 · 编辑精心推荐
以下是Python实现二维傅里叶变换的代码:
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft2, ifft2
def fftshift(img_fft):
row, col = img_fft.shape
mid_row = int(row / 2)
mid_col = int(col / 2)
return np.concatenate((np.concatenate((img_fft[mid_row:, :], img_fft[:mid_row, :]), axis=0)[:, mid_col:],\
np.concatenate((img_fft[mid_row:, :], img_fft[:mid_row, :]), axis=0)[:, :mid_col]), axis=1)
img = plt.imread('image.jpg')
gray = np.dot(img[..., :3], [0.299, 0.587, 0.114])
gray_fft = fft2(gray)
gray_shift = fftshift(gray_fft)
plt.imshow(np.log(np.abs(gray_shift)+1), 'gray')
plt.show()
阅读全文