1、Sobel算子
dst = cv2.Sobel(src,ddepth,dx,dy,ksize)
- ddepth:图像的深度
- dx和dy分别表示水平和竖直方向
- ksize是Sobel算子的大小
img = cv2.imread('pie.png',cv2.IMREAD_GRAYSCALE)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
def cv_show(img,name):
cv2.imshow(name,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize = 3)
cv_show(sobelx,'sobelx')
白到黑是整数,黑到白就是负数了,所有的负数会被截断成0,所以要取绝对值。
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize = 3)
sobelx = cv2.convertScaleAbs(sobelx)
cv_show(sobelx,'sobelx')
sobely = cv2.Sobel(img,cv2.CV_64F,1,0,ksize = 3)
sobely = cv2.convertScaleAbs(sobely)
cv_show(sobely,'sobely')
# 分别计算x和y,再求和
sobelxy = cv2.addWeighted(sobelx,0.5,sobely,0.5,0) # 0.5为权重,0为偏置项(可不用)
cv_show(sobelxy,'sobelxy')
2、Scharr算子--更敏感
3、laplacian算子--对噪音点敏感(更多地与其他算法融合使用