方法
1 一阶梯度算子
正交梯度 : [1,-1], [1,-1]';
robet: 斜线差分(四点差分)
prewitt: 平均差分
sobel: 加权平均差分
检测赋值阈值,可检测边缘的方向
2 二阶导数算子 laplacian算子
模板 [0 -1 0; -1 4 -1;0 -1 0]/4; 方向无关,检测零交叉,可要求过零点的两边的差值大于一定的阈值
3 LoG
高斯滤波后再进行二阶导数,可先对高斯函数求二阶导数然后得到离散化模板,之后用模板和图像卷积
4 canny
以上在matlab中都采用edge实现。
关于零交叉的检测,参考代码,应该是对[- +]和[- 0 +]都进行检测:
% Look for the zero crossings: +-, -+ and their transposes
% We arbitrarily choose the edge to be the negative point
[rx,cx] = find( b(rr,cc) < 0 & b(rr,cc+1) > 0 ...
& abs( b(rr,cc)-b(rr,cc+1) ) > thresh ); % [- +]
e((rx+1) + cx*m) = 1;
[rx,cx] = find( b(rr,cc-1) > 0 & b(rr,cc) < 0 ...
& abs( b(rr,cc-1)-b(rr,cc) ) > thresh ); % [+ -]
e((rx+1) + cx*m) = 1;
[rx,cx] = find( b(rr,cc) < 0 & b(rr+1,cc) > 0 ...
& abs( b(rr,cc)-b(rr+1,cc) ) > thresh); % [- +]'
e((rx+1) + cx*m) = 1;
[rx,cx] = find( b(rr-1,cc) > 0 & b(rr,cc) < 0 ...
& abs( b(rr-1,cc)-b(rr,cc) ) > thresh); % [+ -]'
e((rx+1) + cx*m) = 1;
% Most likely this covers all of the cases. Just check to see if there
% are any points where the LoG was precisely zero:
[rz,cz] = find( b(rr,cc)==0 );
if ~isempty(rz)
% Look for the zero crossings: +0-, -0+ and their transposes
% The edge lies on the Zero point
zero = (rz+1) + cz*m; % Linear index for zero points
zz = find(b(zero-1) < 0 & b(zero+1) > 0 ...
& abs( b(zero-1)-b(zero+1) ) > 2*thresh); % [- 0 +]'
e(zero(zz)) = 1;
zz = find(b(zero-1) > 0 & b(zero+1) < 0 ...
& abs( b(zero-1)-b(zero+1) ) > 2*thresh); % [+ 0 -]'
e(zero(zz)) = 1;
zz = find(b(zero-m) < 0 & b(zero+m) > 0 ...
& abs( b(zero-m)-b(zero+m) ) > 2*thresh); % [- 0 +]
e(zero(zz)) = 1;
zz = find(b(zero-m) > 0 & b(zero+m) < 0 ...
& abs( b(zero-m)-b(zero+m) ) > 2*thresh); % [+ 0 -]
e(zero(zz)) = 1;
5 方向梯度算子
可求得某个方向的最大值