图片对滤波器的冲激响应 impulse response

图像对滤波器的冲激响应实际上就是将滤波器看作一个传递函数,输入为一张只有某个像素点是1,其他像素点为0的空白图像,令该滤波器对这张图像作卷积运算。输出图像就是其滤波器的冲激响应。

import numpy as np
from scipy.signal import correlate
import matplotlib.pyplot as plt 

# Create a gaussian filter
wDeg = 1
nPix = 50
xf = np.linspace(-wDeg/2, wDeg/2, nPix+1).reshape(1, -1)
yf = np.linspace(-wDeg/2, wDeg/2, nPix+1).reshape(-1, 1)
sigma = 0.3  # width of Gaussian (1/e half-width)
gau_filter = np.exp(-(np.power(xf, 2)+np.power(yf, 2))/sigma**2)
# plt.imshow(gau_filter)
# plt.show()

# Create a Dirac image
nPix = 200
dirac_img = np.zeros((nPix + 1, nPix + 1))
dirac_img[nPix//2, nPix//2] = 1
# plt.imshow(dirac_img)
# plt.show()

# Perform impulse response test
# - Dirac image as input
# - Gaussian filter as the system to be tested
# - Output convoluted image as the result image
res_img = correlate(dirac_img, gau_filter)
# plt.imshow(res_img)
# plt.show()

# Display intermediate and final results
plt.figure()
img_list = [dirac_img, gau_filter, res_img]
img_label = ['input image', 'Gaussian filter', 'impulse response image']
for i in range(1, 4):
    plt.subplot(1,3,i)
    plt.imshow(img_list[i-1])
    plt.xticks([])
    plt.yticks([])
    plt.xlabel(img_label[i-1])
plt.show()

最后输出结果如下:

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值