使用不同卷积核对图像进行处理之后的效果

# -*- coding: utf-8 -*-
import cv2
import numpy as np
import matplotlib.pyplot as plt

src = cv2.imread("09-opencv/lena.jpg")
kernels = [
    (u"低通滤波器", np.array([[1, 1, 1], [1, 2, 1], [1, 1, 1]]) * 0.1),
    (u"高通滤波器", np.array([[0.0, -1, 0], [-1, 5, -1], [0, -1, 0]])),
    (u"边缘检测", np.array([[-1.0, -1, -1], [-1, 8, -1], [-1, -1, -1]]))
]

index = 0
fig, axes = plt.subplots(1, 3, figsize=(12, 4.3))
for ax, (name, kernel) in zip(axes, kernels):
    dst = cv2.filter2D(src, -1, kernel)
    ax.imshow(dst[:, :, ::-1])
    ax.set_title(name)
    ax.axis('off')
fig.subplots_adjust(0.02, 0, 0.98, 1, 0.02, 0)
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.show()

猜你喜欢

转载自blog.csdn.net/qq_34000894/article/details/80426445