目录
锐化(高通)空间滤波器钝化掩蔽和高提升滤波锐化(高通)空间滤波器
平滑通过称为低通滤波类似于积分运算锐化通常称为高通滤波微分运算高过(负责细节的)高频,衰减或抑制低频钝化掩蔽和高提升滤波
钝化掩蔽
从原图像中减去一幅钝化(平滑后的)图像
步骤:
模糊原图像从原图像减去模糊后的图像(产生的差称为模板)将模板与原图像相加
令fˉ(x,y)\bar f(x,y)fˉ(x,y)表示模糊后的图像,则有
gmask(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)+kgmask(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≥0k \ge 0k≥0,k=1k = 1k=1时,它是钝化掩蔽,k>1k > 1k>1时,这个过程称为高提升滤波,选择k≤1k \leq 1k≤1可以减少钝化模板的贡献。
# 钝化掩蔽过程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_barax_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_masky_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_31img_dst_1 = img_ori + img_diffimg_dst_1 = np.uint8(normalize(img_dst_1) * 255)img_dst_2 = img_ori + 2 * img_diffimg_dst_2 = np.uint8(normalize(img_dst_2) * 255)img_dst_3 = img_ori - 3 * img_diffimg_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()
第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波16 - 锐化高通滤波器 - 钝化掩蔽和高提升滤波