您的位置:首页 > 其它

图像处理中的卷积---3.高斯卷积计算梯度

2015-11-29 23:30 579 查看
首先,介绍一下梯度的概念:梯度是一个由函数沿各分项导数组成的向量,式[1],


[1]

然后,我们来看一下导数的计算,在离散空间中,我们一般会用f(k) - f(k-1)/(k- (k-1) )来计算导数。

现在我们介绍另外一种基于卷积特性的导数计算方法,由于卷积具有以下性质,[2]


[2]

因而,在图像处理中,一般对gaussian kernel计算导数,得到gd kernel,然后利用gd kernel 对图像卷积处理得到导数。 (选择gaussian kernel计算导数的原因是gaussian kernel具有平滑的特性)

下面附一个MATLAB中计算图像导数的例子:(我们把x方向的导数和y方向的导数组合起来就构成了梯度)



I =  imread( 'cameraman.gif' );
I = double( I );

sigma = 3;
Wx = floor(3*sigma);
% Wx is determined by one property of gaussian function
% that almost all the samples are distributed in [Mu-3Sigma, Mu+3sigma]
x = -Wx:Wx;
g = exp(-(x.^2)/(2*sigma^2));
gp = -(x/sigma).*exp(-(x.^2)/(2*sigma^2));

kernelx = conv2( -gp, g');

Igdx = conv2(I, kernelx);  %Use kernel to convolution with Input image

figure(1);
subplot(2,3,1); imagesc(I); axis image; colormap(gray);       title('Input Image');
subplot(2,3,2); imagesc(kernelx); axis image; colormap(gray);  title('Gd x kernel');
subplot(2,3,3); imagesc(Igdx); axis image; colormap(gray);      title('Output Image');

kernely = conv2( g , -gp');
Igdy = conv2(I, kernely);  %Use kernel to convolution with Input image

subplot(2,3,4); imagesc(I); axis image; colormap(gray);       title('Input Image');
subplot(2,3,5); imagesc(kernely); axis image; colormap(gray);  title('Gd y kernel');
subplot(2,3,6); imagesc(Igdy); axis image; colormap(gray);      title('Output Image');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: