首页 技术 正文
技术 2022年11月6日
0 收藏 351 点赞 662 浏览 3069 个字

收入囊中

  • 拉普拉斯算子
  • LOG算子(高斯拉普拉斯算子)
  • OpenCV Laplacian函数
  • 构建自己的拉普拉斯算子
  • 利用拉普拉斯算子进行图像的锐化

葵花宝典在OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)  我们已经认识了3个一阶差分算子拉普拉斯算子是二阶差分算子。为什么要增加二阶的算子呢?试想一下,假设图像中有噪声,噪声在一阶导数处也会取得极大值从而被当作边缘。然而求解这个极大值也不方便。採用二阶导数后,极大值点就为0了。因此值为0的地方就是边界。

有图有真相。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWJjZDE5OTI3MTln/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center” width=”600″ height=”500″ alt=””>上面是一阶导数。以下是二阶导数

基本理论公式:                                  

离散形式:

  

   
图5-9  拉普拉斯的4种模板

拉普拉斯算子会放大噪声,因此我们採用了LOG算子,就是高斯拉普拉斯算子,先对图像进行高斯模糊。抑制噪声,再求二阶导数。二阶导数为0的地方就是图像的边界。关于LOG算子模版,在OpenCV2马拉松第20圈——blob特征检測原理与实现有具体实现

初识APIAPI不用解释了。和Sobel全然一样!

C++: void Laplacian(InputArray src,
OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
 
  • src – Source image.
  • dst – Destination image of the same size and the same number of channels as src .
  • ddepth – Desired depth of the destination image.
  • ksize – Aperture size used to compute the second-derivative filters. See getDerivKernels() for
    details. The size must be positive and odd.
  • scale – Optional scale factor for the computed Laplacian 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.

This is done when ksize > 1 . When ksize == 1 ,
the Laplacian is computed by filtering the image with the following  aperture:

荷枪实弹我们先调用API来实现

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"using namespace cv;int main( int, char** argv )
{ Mat src, src_gray;
int kernel_size = 3;
const char* window_name = "Laplace Demo"; src = imread( argv[1] );
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
cvtColor( src, src_gray, CV_RGB2GRAY );
namedWindow( window_name, CV_WINDOW_AUTOSIZE ); Mat dst, abs_dst;
Laplacian( src_gray, dst, CV_16S, kernel_size);
convertScaleAbs( dst, abs_dst ); imshow( window_name, abs_dst );
waitKey(0);
return 0;
}

效果图:

以下,我们用之前讲过的自己定义滤波实现,採用

1 1 1
1 -8 1
1 1 1

这样的形式的算子,代码例如以下

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv; int main( int, char** argv )
{
Mat src,gray,Kernel; src = imread( argv[1] );
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
cvtColor( src, gray, CV_RGB2GRAY );
namedWindow("dstImage", 1); Kernel = (Mat_<double>(3,3) << 1, 1, 1, 1, -8, 1, 1, 1, 1);
Mat grad,abs_grad;
filter2D(gray, grad, CV_16S , Kernel, Point(-1,-1));
convertScaleAbs( grad, abs_grad ); imshow("dstImage", abs_grad);
waitKey();
return 0;
}

效果图就不发了,跟上面差点儿相同

举一反三拉普拉斯算子有没有跟多的应用,当然有。比方图像锐化。因为拉普拉斯是一种微分算子,它可增强图像中灰度突变的区域,减弱灰度的缓慢变化区域。因此,锐化处理可选择拉普拉斯算子对原图像进行处理。产生描写叙述灰度突变的图像。再将拉普拉斯图像与原始图像叠加而产生锐化图像。

拉普拉斯锐化的基本方法能够由下式表示:

锐化代码

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv; int main( int, char** argv )
{
Mat src,gray; src = imread( argv[1] );
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
cvtColor( src, gray, CV_RGB2GRAY );
namedWindow("srcImage", 1);
namedWindow("dstImage", 1); Mat grad,abs_grad;
Laplacian( gray, grad, CV_16S, 3);
convertScaleAbs( grad, abs_grad );
Mat sharpped = gray + abs_grad; imshow("srcImage", gray);
imshow("dstImage", sharpped);
waitKey();
return 0;
}

效果图:

有放大噪声(非常难避免)

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,111
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922