图像梯度-scharr算子和sobel算子对比

在这里插入图片描述
大小一样,故计算量一样。
scharr算子临近像素的权重更大,故精确度更高。

对比两种算子的处理效果。发现scharr算子能计算出更小的梯度变化

import cv2
a=cv2.imread('image\\lena256.bmp')

sobelx=cv2.Sobel(a,cv2.CV_64F,1,0)
sobelx=cv2.convertScaleAbs(sobelx)
sobely=cv2.Sobel(a,cv2.CV_64F,0,1)
sobely=cv2.convertScaleAbs(sobely)
sobelxy=cv2.addWeighted(sobelx,0.5,sobely,0.5,0)

scharrx=cv2.Scharr(a,cv2.CV_64F,1,0)
scharrx=cv2.convertScaleAbs(scharrx)
scharry=cv2.Scharr(a,cv2.CV_64F,0,1)
scharry=cv2.convertScaleAbs(scharry)
scharrxy=cv2.addWeighted(scharrx,0.5,scharry,0.5,0)

cv2.imshow('a',a)
cv2.imshow('sobelxy',sobelxy)
cv2.imshow('scharrxy',scharrxy)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/sundanping_123/article/details/86503533