您的位置:首页 > 编程语言 > Python开发

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

2014-07-27 16:44 591 查看
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) → None
Parameters: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:


本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/

# -*- 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 滤波更精确的结果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐