[VP] 拉普拉斯算子 Laplacian Filter

拉普拉斯算子


拉普拉斯算子

长这样:

[ − 1 2 − 1 − 1 2 − 1 − 1 2 − 1 ] \begin{bmatrix} -1 & 2 &-1 \\ -1 & 2 &-1 \\-1 & 2 &-1 \end{bmatrix} 111222111

性质

Image = np.array([[0, 0, 0, 0, 0, 0], 
                  [0, 1, 5, 9, 7, 0], 
                  [0, 1, 5, 9, 7, 0], 
                  [0, 1, 5, 9, 7, 0], 
                  [0, 1, 5, 9, 7, 0], 
                  [0, 0, 0, 0, 0, 0]])

Kernel = [[-1, 2, -1], [-1, 2, -1], [-1, 2, -1]]

ax1 = plt.subplot(1,2,1)
plt.imshow(Image)
plt.title('Image')

ax1 = plt.subplot(1,2,2)
plt.imshow(Kernel)
plt.title('Kernel')


def convolution(Image, Kernel):
    count = 0
    for i in range(0, 3):
        for j in range(0, 3):
            count += Image[2-i][2-j]*Kernel[i][j]
    return count

def correlation(Image, Kernel):
    count = 0
    for i in range(0, 3):
        for j in range(0, 3):
            count += Image[i][j]*Kernel[i][j]
    return count


result1 = [[0, 0, 0, 0], 
          [0, 0, 0, 0],
          [0, 0, 0, 0], 
          [0, 0, 0, 0]]

for i in range(4):
    for j in range(4):
        result1[i][j] = convolution(Image[i:i+3, j:j+3], Kernel)


result2 = [[0, 0, 0, 0], 
          [0, 0, 0, 0],
          [0, 0, 0, 0], 
          [0, 0, 0, 0]]

for i in range(4):
    for j in range(4):
        result2[i][j] = correlation(Image[i:i+3, j:j+3], Kernel)


_, ax = plt.subplots(1, 2, figsize = (10, 10))

ax[0].imshow(result1)
ax[0].set_title('Convolution Result')
ax[1].imshow(result2)
ax[1].set_title('Correlation Result')

在这里插入图片描述

从结果看出,用拉普拉斯算子对图像做卷积和关联操作,其结果是一样的,因为拉普拉斯算子本身旋转 180° 的结果还是它本身

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

是土豆大叔啊!

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

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

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

打赏作者

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

抵扣说明:

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

余额充值