龙空技术网

拉普拉斯算子 提取图像边缘信息

拉格朗日学徒 76

前言:

现时各位老铁们对“拉普拉斯算子例题步骤”大致比较看重,朋友们都需要知道一些“拉普拉斯算子例题步骤”的相关内容。那么小编在网络上搜集了一些有关“拉普拉斯算子例题步骤””的相关内容,希望各位老铁们能喜欢,我们快快来学习一下吧!

# -*- coding: utf-8 -*-"""Created on Sat Apr 18 15:48:04 2020@author: Surface Pro"""import numpy as npimport cv2from matplotlib import pyplot as pltdef laplace2(img, sx=1.0):    row = np.zeros((1,img.shape[1]))    img = np.row_stack((row,img,row))        col = np.zeros((img.shape[0],1))    img = np.column_stack((col,img,col))        if sx == 1.0:        g = np.array(((0,1,0),(1,-4,1),(0,1,0)))    else:        g = np.array(((1,1,1),(1,-8,1),(1,1,1)))            g = -1 * g            re = np.zeros_like(img)        for i  in range(1, img.shape[0]-1):        for j in range(1,img.shape[1]-1):            re[i,j]=(img[i-1:i+2, j-1:j+2]*g).sum()            re = re[1:-1, 1:-1]        return reimg = cv2.imread(r'../img1.jpg')gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)img2 = laplace2(gray,sx=1.0)plt.imshow(img)plt.imshow(gray)plt.imshow(img2)plt.show()

标签: #拉普拉斯算子例题步骤