python对数据集使用2维卷积运算对二值化后的10张图像进行处理实现边缘检测。
以下是使用Python实现对二值化图像进行边缘检测的代码:
import numpy as np
import cv2
# 读取二值化图像
img = cv2.imread('binary_image.png', 0)
# 定义卷积核
kernel = np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]])
# 进行2维卷积运算
edges = cv2.filter2D(img, -1, kernel)
# 显示边缘检测结果
cv2.imshow('Edges', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
其中,cv2.imread('binary_image.png', 0) 读取了名为 binary_image.png 的二值化图像,np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]) 定义了一个 3x3 的卷积核,cv2.filter2D(img, -1, kernel) 对二值化图像进行了2维卷积运算,最终得到了边缘检测结果,并通过 cv2.imshow 显示出来
原文地址: https://www.cveoy.top/t/topic/eCUg 著作权归作者所有。请勿转载和采集!