傅里叶变换经滤波处理及傅里叶逆变换

傅里叶变换经滤波处理及傅里叶逆变换,第1张

import cv2
import matplotlib.pyplot as plt
import numpy as np


def FT(image):
    # image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # 快速傅里叶变换得到频率分布
    f = np.fft.fft2(image)
    # 默认结果中心点是在图像左上角
    # 调用函数转移到中心位置
    fshift = np.fft.fftshift(f)
    # fft结果是复数 其绝对值结果是振幅
    fimg = np.abs(fshift)
    return fimg, fshift


def HighPassFilter(FTImg, fshift):
    rows, cols = FTImg.shape
    crow, ccols = int(rows / 2), int(cols / 2)
    fshift[crow - 30: crow + 30, ccols - 30:ccols + 30] = 0
    return fshift


def IFT(parameter):
    # 傅里叶逆变换
    ishift = np.fft.ifftshift(parameter)
    iimg = np.fft.ifft2(ishift)
    iimg = np.abs(iimg)
    return iimg


# 读取图像
img = cv2.imread("D:\Picture\12.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imshow("img",img)
# cv2.waitKey()
# 显示结果
mg, ft = FT(img)
hft = HighPassFilter(mg, ft)
IFT(hft)
plt.subplot(131), plt.imshow(img, "gray"), plt.title("Original Fourier")
plt.axis("off")
plt.subplot(132), plt.imshow(mg, "gray"), plt.title("Fourier Fourier")
plt.axis("off")
plt.subplot(133), plt.imshow(IFT(hft), "gray"), plt.title("Inverse Fourier Fourier")
plt.axis("off")
plt.show()

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/732238.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-27
下一篇2022-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存