第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波16 - 锐化高通滤波器 - 钝化掩蔽和高提升滤波

锐化(高通)空间滤波器

  • 平滑通过称为低通滤波
  • 类似于积分运算
  • 锐化通常称为高通滤波
  • 微分运算
  • 高过(负责细节的)高频,衰减或抑制低频

钝化掩蔽和高提升滤波

  • 钝化掩蔽

  • 从原图像中减去一幅钝化(平滑后的)图像

  • 步骤:

  1. 模糊原图像
  2. 从原图像减去模糊后的图像(产生的差称为模板)
  3. 将模板与原图像相加

f ˉ ( x , y ) \bar f(x,y) fˉ(x,y)表示模糊后的图像,则有
g m a s k ( x , y ) = f ( x , y ) − f ˉ ( x , y ) (3.55) g_{mask}(x, y) = f(x, y) - \bar f(x,y) \tag{3.55} gmask(x,y)=f(x,y)fˉ(x,y)(3.55)
g ( x , y ) = f ( x , y ) + k g m a s k ( x , y ) (3.56) g(x,y) = f(x,y) + k g_{mask}(x, y) \tag{3.56} g(x,y)=f(x,y)+kgmask(x,y)(3.56)
权值 k ≥ 0 k \ge 0 k0 k = 1 k = 1 k=1时,它是钝化掩蔽 k > 1 k > 1 k>1时,这个过程称为高提升滤波,选择 k ≤ 1 k \leq 1 k1可以减少钝化模板的贡献。

# 钝化掩蔽过程
y = np.linspace(0.4,1, 7)
y = np.pad(y, (4, 4), mode='constant', constant_values=[0.4, 1])

fig = plt.figure(figsize=(16, 8))
ax_1 = fig.add_subplot(2, 2, 1)
ax_1.plot(y, '-', label="y")
ax_1.legend(loc='best', fontsize=12)

kernel = np.array([0.2, 0.6, 0.2])
y_bar = np.convolve(y, kernel, 'same')

y_bar = y_bar[1:-1]
ax_2 = fig.add_subplot(2, 2, 2)
ax_2.plot(y_bar, '-', label='Smooth')
ax_2.legend(loc='best', fontsize=12)

y = y[1:-1]
y_mask = y - y_bar

ax_3 = fig.add_subplot(2, 2, 3)
ax_3.plot(y_mask, '-', label='y - y_bar')
ax_3.legend(loc='best', fontsize=12)

y_dst = y + y_mask
y_dst = normalize(y_dst)
ax_4 = fig.add_subplot(2, 2, 4)
ax_4.plot(y_dst, '-', label='y + y_mask')
ax_4.legend(loc='best', fontsize=12)

plt.tight_layout()
plt.show()

在这里插入图片描述

# 纯化掩蔽与高提升滤波
img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH03/Fig0338(a)(blurry_moon).tif", 0)

kernel_31 = gauss_kernel((9, 9), sigma=1)
img_31 = separate_kernel_conv2D(img_ori, kernel=kernel_31)
img_31 = np.uint8(normalize(img_31) * 255)

img_diff = img_ori - img_31

img_dst_1 = img_ori + img_diff
img_dst_1 = np.uint8(normalize(img_dst_1) * 255)

img_dst_2 = img_ori + 2 * img_diff
img_dst_2 = np.uint8(normalize(img_dst_2) * 255)

img_dst_3 = img_ori - 3 * img_diff
img_dst_3 = np.uint8(normalize(img_dst_3) * 255)

plt.figure(figsize=(15, 12))
plt.subplot(2,3,1), plt.imshow(img_ori,   'gray', vmax=255), plt.title("Original"), plt.xticks([]), plt.yticks([])
plt.subplot(2,3,2), plt.imshow(img_31,    'gray', vmax=255), plt.title("Smooth"), plt.xticks([]), plt.yticks([])
plt.subplot(2,3,3), plt.imshow(img_diff,  'gray', vmax=255), plt.title("Diff"), plt.xticks([]), plt.yticks([])
plt.subplot(2,3,4), plt.imshow(img_dst_1, 'gray', vmax=255), plt.title("k = 1"), plt.xticks([]), plt.yticks([])
plt.subplot(2,3,5), plt.imshow(img_dst_2, 'gray', vmax=255), plt.title("k = 2"), plt.xticks([]), plt.yticks([])
plt.subplot(2,3,6), plt.imshow(img_dst_2, 'gray', vmax=255), plt.title("k = 3"), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()

在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasneik

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值