问题的描述
我们需要通过一些图像处理的手段,将a图中图像的轮廓提取出来,结果类似于b图。
解决思路
使用Laplacian
看到这个问题,我想到的第一办法就是拉普拉斯算子。ok,沿着这个思路,我通过opencv在windows平台上进行了一些测试。
Laplacian 算子的定义:
- Laplace(f)=(∂2f)(∂x2)+(∂2f)(∂y2)
这里求导使用的方法是Sobel算子,关于Sobel算子请看2.3。
在opencv中Laplacian的函数原型
CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
int ksize = 1, double scale = 1, double delta = 0,
int borderType = BORDER_DEFAULT );
在opencv源代码中就已经说明了这个函数的使用,如下:
@param src Source image.
@param dst Destination image of the same size and the same number of channels as src .
@param ddepth Desired depth of the destination image.
@param ksize Aperture size used to compute the second-derivative filters. See getDerivKernels for details. The size must be positive and odd.
@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is applied. See getDerivKernels for details.
@param delta Optional delta value that is added to the results prior to storing them in dst .
@param borderType Pixel extrapolation method, see cv::BorderTypes
当ksize=3时,Laplacian()函数的孔径为
- ∣∣∣∣0101−41010∣∣∣∣