傅里叶变换是一种将信号从时域转换到频域的数学方法,时常作用在图像领域。
python中的傅里叶变换主要有两种——numpy与cv2。
首先讲解numpy中的实现方式:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# 读入图像
img_org = cv2.imread('dog.jpeg',0)
# 进行傅里叶变换并将低频区移至中心
img_fft_shift = np.fft.fftshift(np.fft.fft2(img_org) )
# 将像素点限制在一定区域内,便于可视化显示(防止像素点超过255无法正常显示)
img_trans = np.log(np.abs(img_fft_shift))
# 将值扩大到0-255之间
img_expand = int(255/np.max(img_trans))*img_trans
# 可视化
plt.figure(figsize=(8,10))
plt.subplot(121) ,plt.imshow(img_org, cmap = 'gray') ,plt.title('original')
plt.subplot(122) ,plt.imshow(img_expand, cmap = 'gray') ,plt.title('result')
plt.show()
运行结果:
第二种cv2中的实现方式: