边缘检测函数:Canny() Sobel() Laplacian()scharr滤波器

来源:互联网 发布:pdf.js跨域请求file 编辑:程序博客网 时间:2024/05/22 10:48
边缘:灰度或结构等信息的突变处,边缘是一个区域的结束,也是另一个区域的开始,利用该特征可以分割图像,这也是边缘检测的意义。


Canny()作用:检测图像边缘
应用:
int main()
{

Mat src=imread("lou.jpg",0);
Mat dst,temp;
blur(src,src,Size(5,5));
Canny(src,dst,10,20,5);  //第3,4个参数为两个阙值,比例大概为1:3到1:2之间
temp=Scalar::all(0);
src.copyTo(temp,dst);  //边缘图dst作为掩膜,将原图和边缘叠加放到temp当中
imshow("a",temp);
waitKey(0);
}
Sobel()作用:检测图像边缘
原理:计算一阶、二阶、三阶或者混合图像差分
int main()
{
Mat x_dst,y_dst;
Mat abs_x_dst,abs_y_dst;
Mat dst,result;
Mat src=imread("lou.jpg",0);
Sobel(src,x_dst,-1,1,0,3,1,0,4);
Sobel(src,y_dst,-1,0,1,3,1,0,4);
convertScaleAbs(x_dst,abs_x_dst);
convertScaleAbs(y_dst,abs_y_dst);
addWeighted(abs_x_dst,0.5,abs_y_dst,0.5,0,result);
imshow("a",result);
waitKey(0);
}
Laplacian算子
定义为梯度grad的散度div
int main()
{
Mat x_dst,y_dst;
Mat abs_x_dst,abs_y_dst;
Mat dst,result;
Mat src=imread("lou.jpg",0);
GaussianBlur(src,src,Size(3,3),0,0,BORDER_DEFAULT);
Laplacian(src,dst,-1,3,1,0,4);
int a=dst.depth();
cout<<a<<endl;
imshow("a",dst);
waitKey(0);
}
Scharr滤
波器
计算x和y方向上的差分
0 0
原创粉丝点击