比较他们的梯度值大小,若z5的梯度值大于z4、z6,且满足这该点被判断为边缘上的点
4)但这样得到的边缘可能还包含噪声或者虚假边缘,canny算子还采用双阈值法检测和连接边缘,首先用低阈值在检测最大值梯度所在点作为边缘点的图像中滤掉一部分噪声,再与强阈值比较后的具有较少假边缘但是边缘不连续的图像叠加找出封闭边缘,最后得到较好效果的边缘检测图像。
5)基于canny算子的边缘检测算法在Matlab中的调用方式如下:
BW = edge(I,'canny')
直接调用,模板、方差均采用matlab默认值
BW = edge(I,'canny',thresh)
thresh为指定阈值,注,不指定时默认为lowThresh=0.0375,highThresh=0.0938
BW = edge(I,'canny',thresh,SIGMA)
SIGMA为高斯滤波器的方差,默认为1
[BW,thresh] = edge(I,'canny',...)
返回Matlab根据灰度直方图自适应计算出的高低阈值(滞后阈值)thresh
6)Matlab实现canny算子边缘检测的主体代码如下:
I = imread('pout.tif');
a = im2single(I);
%%%%%%高斯平滑%%%%%%%%%%%%%%%%%%%%、
% Create an even-length 1-D separable Derivative of Gaussianfilter
% Determine filter length
x =-4:4;%Matlab默认滤波模板长度
% Create 1-D Gaussian Kernel
c = 1/(sqrt(2*pi));
gaussKernel = c * exp(-(x.^2)/2);
% Normalize to ensure kernel sums to one归一化高斯核
gaussKernel = gaussKernel/sum(gaussKernel);%
% Create 1-D Derivative of Gaussian Kernel高斯核求梯度
derivGaussKernel = gradient(gaussKernel);%
% Normalize to ensure kernel sums to zero
negVals = derivGaussKernel < 0;
posVals = derivGaussKernel > 0;
derivGaussKernel(posVals) =derivGaussKernel(posVals)/sum(derivGaussKernel(posVals));
derivGaussKernel(negVals) =derivGaussKernel(negVals)/abs(sum(derivGaussKernel(negVals)));
% Compute smoothed numerical gradient of image I along x(horizontal)
% direction. GX corres
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-33967-5.html
只不过马云的办公室和祖宗的墓地风水好