python机器视觉算法_数学之路-python计算实战(22)-机器视觉-sobel非线性滤波

sobel非线性滤波,采用梯度模的近似方式

Sobel

Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.C++:void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, intksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )Python:cv2.Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]]) → dstC:void cvSobel(const CvArr* src, CvArr* dst, int xorder, int yorder, intaperture_size=3 )Python:cv.Sobel(src, dst, xorder, yorder, apertureSize=3) → NoneParameters:src – input image.

dst – output image of the same size and the same number of channels as src .

ddepth –output image depth; the following combinations of src.depth() andddepth are supported:src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F

src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F

src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F

src.depth() = CV_64F, ddepth = -1/CV_64F

when ddepth=-1, the destination image will have the same depth as the source; in the case of 8-bit input images it will result in truncated derivatives.

xorder – order of the derivative x.

yorder – order of the derivative y.

ksize – size of the extended Sobel kernel; it must be 1, 3, 5, or 7.

scale – optional scale factor for the computed derivative values; by default, no scaling is applied (seegetDerivKernels() for details).

delta – optional delta value that is added to the results prior to storing them in dst.

borderType – pixel extrapolation method (seeborderInterpolate() for details).

In all cases except one, the

 separable kernel is used to calculate the derivative. When 

 , the 

 or 

 kernel is used (that is, no Gaussian smoothing is done). ksize = 1 can only be used for the first or the second x- or y- derivatives.

There is also the special value ksize = CV_SCHARR (-1) that corresponds to the

Scharr filter that may give more accurate results than the 

 Sobel. The Scharr aperture is

for the x-derivative, or transposed for the y-derivative.

The function calculates an image derivative by convolving the image with the appropriate kernel:

The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less resistant to the noise. Most often, the function is called with ( xorder= 1, yorder = 0, ksize = 3) or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first case corresponds to a kernel of:

The second case corresponds to a kernel of:

# -*- coding: utf-8 -*-

#非线性锐化滤波,sobel算子变换

#code:myhaspl@myhaspl.com

import cv2

fn="test6.jpg"

myimg=cv2.imread(fn)

img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)

jgimg=cv2.Sobel(img,0,1,1)

cv2.imshow(‘src‘,img)

cv2.imshow(‘dst‘,jgimg)

cv2.waitKey()

cv2.destroyAllWindows()

Sobel

使用扩展 Sobel 算子计算一阶、二阶、三阶或混合图像差分void cvSobel( const CvArr* src, CvArr* dst, int xorder, int yorder, int aperture_size=3 );src输入图像.dst输出图像.xorderx 方向上的差分阶数yordery 方向上的差分阶数aperture_size扩展 Sobel 核的大小,必须是 1, 3, 5 或 7。 除了尺寸为 1, 其它情况下, aperture_size ×aperture_size 可分离内核将用来计算差分。对 aperture_size=1的情况, 使用 3x1 或 1x3 内核 (不进行高斯平滑操作)。这里有一个特殊变量 CV_SCHARR (=-1),对应 3x3 Scharr 滤波器,可以给出比 3x3 Sobel 滤波更精确的结果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值