收入囊中
  • 差分在边缘检測的角色
  • Sobel算子
  • OpenCV sobel函数
  • OpenCV Scharr函数
  • prewitt算子
  • Roberts算子

葵花宝典
差分在边缘检測究竟有什么用呢?先看以下的图片
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)作为人,我们能够非常easy发现图中红圈有边界,边界处肯定是非常明显,变化陡峭的,在数学中,什么能够表示变化的快慢,自然就是导数,微分了。

想像有例如以下的一维图片。
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)红圈处变化最陡峭,再看导数图


OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)红圈在最高值,也就是导数能够非常好表示边缘,由于变化非常剧烈


图像中的Sobel算子
  1. 是离散差分算子.
  2. 结合了高斯滤波.

OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)是原始图像:

  1. 我们计算水平和竖直方向的梯度:

    1. 水平方向: Gx是我们Kernel size为3的水平sober算子,与I作卷积

      OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)

    2. 竖直方向:Gy是我们Kernel size为3的水平sober算子,与I作卷积

      OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)

  2. 对每一个点,再计算以下的值,得到方向无关梯度

    OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)

    有时候也能够这样计算:

    OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)





初识API
C++: void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, intborderType=BORDER_DEFAULT )
 
  • src – 输入.
  • dst – 输出
  • ddepth –
    output image depth; the following combinations of src.depth() and ddepth 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.这里要特别注意了,我们的depth不能为-1,由于我们的输入是uchar8类型的,而算出来的值可能>255也可能 <0 ,都会被截断,CV_16S是推荐的

  • xorder – order of the derivative x.
  • yorder – order of the derivative y.
  • ksize – sobel核大小,必须为1, 3, 5, or 7.
  • scale – 扩大系数
  • delta – 附加系数
  • borderType – 边界类型

计算的时候,利用了可分离的滤波进行加速(Ksize=1的时候,用了1*3和 3*1的算子,无法加速)

当Ksize = 3,Sobel採用的算子会不准确,因此还有特殊的值ksize = CV_SCHARR(-1) 相当于使用 OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts) Scharr filter 比 OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)Sobel算子能获得更准确的结果. Scharr 算子例如以下

OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)



C++: void Scharr(InputArray src, OutputArray dst, int ddepth, int dx, int dy, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
 
  • src – input image.
  • dst – output image of the same size and the same number of channels as src.
  • ddepth – output image depth (see Sobel() for the list of supported combination of src.depth() and ddepth).
  • dx – order of the derivative x.
  • dy – order of the derivative y.
  • scale – optional scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels() for details).
  • delta – optional delta value that is added to the results prior to storing them in dst.
  • borderType – pixel extrapolation method (see borderInterpolate() for details).

The function computes the first x- or y- spatial image derivative using the Scharr operator. The call

OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)

is equivalent to

OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)

用法一样~~


荷枪实弹

效果图:
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)



举一反三
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)该算子与Sobel算子类似,仅仅是权值有所变化,但两者实现起来功能还是有差距的,据经验得知Sobel要比Prewitt更能准确检測图像边缘。

OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)Robert算子是一种梯度算子,它用交叉的差分表示梯度,是一种利用局部差分算子寻找边缘的算子,对具有陡峭的低噪声的图像效果最好:

以下我们来用prewitt算子作边缘检測,还记得我们曾经在http://blog.csdn.net/abcd1992719g/article/details/24625805用过的自己定义滤波不,以下我们又要用上了。

效果图:
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)





计算机视觉讨论群162501053
转载请注明:http://blog.csdn.net/abcd1992719g


相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2021-12-02
  • 2021-10-05
  • 2021-10-14
  • 2022-01-13
  • 2022-12-23
  • 2021-07-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-02-06
  • 2021-05-12
  • 2021-04-26
  • 2022-01-06
相关资源
相似解决方案