码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-07-28 00:04:30      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:图像算法   机器视觉   


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]]]]]) → dst
C: 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_8Uddepth = -1/CV_16S/CV_32F/CV_64F
    • src.depth() = CV_16U/CV_16Sddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_32Fddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_64Fddepth = -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 bubuko.com,布布扣 separable kernel is used to calculate the derivative. When bubuko.com,布布扣 , the bubuko.com,布布扣 or bubuko.com,布布扣 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 bubuko.com,布布扣Scharr filter that may give more accurate results than the bubuko.com,布布扣 Sobel. The Scharr aperture is

bubuko.com,布布扣

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

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

bubuko.com,布布扣

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:

bubuko.com,布布扣

The second case corresponds to a kernel of:

bubuko.com,布布扣


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

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
输出图像.
xorder
x 方向上的差分阶数
yorder
y 方向上的差分阶数
aperture_size
扩展 Sobel 核的大小,必须是 1, 3, 5 或 7。 除了尺寸为 1, 其它情况下, aperture_size ×aperture_size 可分离内核将用来计算差分。对 aperture_size=1的情况, 使用 3x1 或 1x3 内核 (不进行高斯平滑操作)。这里有一个特殊变量 CV_SCHARR (=-1),对应 3x3 Scharr 滤波器,可以给出比 3x3 Sobel 滤波更精确的结果。
bubuko.com,布布扣

数学之路-python计算实战(22)-机器视觉-sobel非线性滤波,布布扣,bubuko.com

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

标签:图像算法   机器视觉   

原文地址:http://blog.csdn.net/myhaspl/article/details/38173343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!