现在算力提升了,最常用的一阶差分边缘检测算子已经不是Sobel算子了,而是高斯一阶微分。
高斯一阶微分
顾名思义,高斯函数的一阶导数。
Derivative of Gaussian 1D
一维直接扩展到二维。
禹晶、肖创柏、廖庆敏《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》P238
MATLAB中的实现。
t = (-width:width);
gau = exp(-(t.*t)/(2*ssq))/(2*pi*ssq); % the gaussian 1D filter
% Find the directional derivative of 2D Gaussian (along X-axis)
% Since the result is symmetric along X, we can get the derivative along
% Y-axis simply by transposing the result for X direction.
[x,y]=meshgrid(-width:width,-width:width);
dgau2D=-x.*exp(-(x.*x+y.*y)/(2*ssq))/(pi*ssq);
% Convolve the filters with the image in each direction
% The canny edge detector first requires convolution with
% 2D Gaussian, and then with the derivative of a Gaussian.
% Since Gaussian filter is separable, for smoothing, we can use
% two 1D convolutions in order to achieve the effect of convolving
% with 2D Gaussian. We convolve along rows and then columns.
%smooth the image out
aSmooth=imfilter(a,gau,'conv','replicate'); % run the filter across rows
aSmooth=imfilter(aSmooth,gau','conv','replicate'); % and then across columns
%apply directional derivatives
ax = imfilter(aSmooth, dgau2D, 'conv','replicate');
ay = imfilter(aSmooth, dgau2D', 'conv','replicate');
mag = sqrt((ax.*ax) + (ay.*ay));
magmax = max(mag(:));
if magmax>0
mag = mag / magmax; % normalize
end
Sobel
Sobel算子可以分解为一步高斯平滑和一步中心差分。所以,它可以看做高斯一阶微分的整数近似形式。
Sobel算子的数学推导是四个方向的相加,模板推导出来后,我们可以从上面的角度解释。