图像梯度--三种算子

1、Sobel算子

G_{x}=\begin{bmatrix} -1 &0 &+1 \\ -2& 0 & +2\\ -1& 0 & +1 \end{bmatrix}\ast A and G_{y}=\begin{bmatrix} -1 &-2 &+1 \\ 0& 0 & 0\\ +1& +2 & +1 \end{bmatrix}\ast A

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算子--更敏感

G_{x}=\begin{bmatrix} -3 &0 &+3 \\ -10& 0 & +10\\ -3& 0 & +3 \end{bmatrix}\ast A and G_{y}=\begin{bmatrix} -3 &-10 &+3 \\ 0& 0 & 0\\ +3& -10 & -3 \end{bmatrix}\ast A

3、laplacian算子--对噪音点敏感(更多地与其他算法融合使用

G=\begin{bmatrix} 0&1 &0 \\ 1& -4 & 1\\ 0& 1 & 0 \end{bmatrix} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值