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

来源:互联网 发布:linux追加分区大小 编辑:程序博客网 时间:2024/06/06 07:10


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 \texttt{ksize} \times\texttt{ksize} separable kernel is used to calculate the derivative. When \texttt{ksize = 1} , the 3 \times 1 or 1 \times 3 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 3\times3Scharr filter that may give more accurate results than the 3\times3 Sobel. The Scharr aperture is

\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}

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

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

\texttt{dst} =  \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}

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:

\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}

The second case corresponds to a kernel of:

\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}


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

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


# -*- coding: utf-8 -*-   #非线性锐化滤波,sobel算子变换#code:myhaspl@myhaspl.comimport cv2fn="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 滤波更精确的结果。

0 0