圖像處理-線性濾波-2 圖像微分(1、2階導數和拉普拉斯算子)

http://www.cnblogs.com/pegasus/archive/2011/05/20/2051780.html  

更復雜些的濾波算子一般是先利用高斯濾波來平滑,然後計算其1階和2階微分。由於它們濾除高頻和低頻,因此稱為帶通濾波器(band-pass filters)。

在介紹具體的帶通濾波器前,先介紹必備的圖像微分知識。

1 一階導數

連續函數,其微分可表達為image ,或image                         (1.1)

對於離散情況(圖像),其導數必須用差分方差來近似,有

                                   image,前向差分 forward differencing                  (1.2)

                                   image ,中心差分 central differencing                     (1.3)

1)前向差分的Matlab實現

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function dimg = mipforwarddiff(img,direction)
% MIPFORWARDDIFF     Finite difference calculations
%
%   DIMG = MIPFORWARDDIFF(IMG,DIRECTION)
%
%  Calculates the forward-difference for a given direction
%  IMG       : input image
%  DIRECTION : 'dx' or 'dy'
%  DIMG      : resultant image
%
%   See also MIPCENTRALDIFF MIPBACKWARDDIFF MIPSECONDDERIV
%   MIPSECONDPARTIALDERIV
 
%   Omer Demirkaya, Musa Asyali, Prasana Shaoo, ... 9/1/06
%   Medical Image Processing Toolbox
 
imgPad = padarray(img,[1 1], 'symmetric' , 'both' );%將原圖像的邊界擴展
[row,col] = size(imgPad);
dimg = zeros(row,col);
switch (direction)  
case 'dx' ,
    dimg(:,1:col-1) = imgPad(:,2:col)-imgPad(:,1:col-1);%x方向差分計算,
case 'dy' ,
    dimg(1:row-1,:) = imgPad(2:row,:)-imgPad(1:row-1,:);
otherwise, disp( 'Direction is unknown' );
end;
dimg = dimg(2:end-1,2:end-1);

2)中心差分的Matlab實現

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function dimg = mipcentraldiff(img,direction)
% MIPCENTRALDIFF     Finite difference calculations
%
%   DIMG = MIPCENTRALDIFF(IMG,DIRECTION)
%
%  Calculates the central-difference for a given direction
%  IMG       : input image
%  DIRECTION : 'dx' or 'dy'
%  DIMG      : resultant image
%
%   See also MIPFORWARDDIFF MIPBACKWARDDIFF MIPSECONDDERIV
%   MIPSECONDPARTIALDERIV
 
%   Omer Demirkaya, Musa Asyali, Prasana Shaoo, ... 9/1/06
%   Medical Image Processing Toolbox
 
img = padarray(img,[1 1], 'symmetric' , 'both' );
[row,col] = size(img);
dimg = zeros(row,col);
switch (direction)
     case 'dx' ,
         dimg(:,2:col-1) = (img(:,3:col)-img(:,1:col-2))/2;
     case 'dy' ,
         dimg(2:row-1,:) = (img(3:row,:)-img(1:row-2,:))/2;
     otherwise,
         disp( 'Direction is unknown' );
end
dimg = dimg(2:end-1,2:end-1);
?
1
  

實例:技術圖像x方向導數

?
1
2
I = imread( 'coins.png' ); figure; imshow(I);
Id = mipforwarddiff(I, 'dx' ); figure, imshow(Id);

      image image

    原圖像                                                   x方向1階導數

 

2 圖像梯度(Image Gradient)

圖像I的梯度定義為image  ,其幅值為image 。出於計算性能考慮,幅值也可用image 來近似。

Matlab函數

1)gradient:梯度計算

2)quiver:以箭頭形狀繪制梯度。注意放大下面最右側圖可看到箭頭,由於這裡計算橫豎兩個方向的梯度,因此箭頭方向都是水平或垂直的。

實例:仍采用上面的原始圖像

?
1
2
3
4
5
I = double (imread( 'coins.png' ));
[dx,dy]=gradient(I);
magnitudeI=sqrt(dx.^2+dy.^2);
figure;imagesc(magnitudeI);colormap(gray);%梯度幅值
hold on;quiver(dx,dy);%疊加梯度方向

        image image

                         梯度幅值                                   梯度幅值+梯度方向

 

3 二階導數

對於一維函數,其二階導數image ,即image 。它的差分函數為

                                 image                  (3.1)

 

3.1 普拉斯算子(laplacian operator)

3.1.2 概念

拉普拉斯算子是n維歐式空間的一個二階微分算子它定義為兩個梯度向量算子的內積

                           image       (3.2)

其在二維空間上的公式為:    image                (3.3)

 

對於1維離散情況,其二階導數變為二階差分

1)首先,其一階差分為image

2)因此,二階差分為

           image

3)因此,1維拉普拉斯運算可以通過1維卷積核image 實現

 

對於2維離散情況(圖像),拉普拉斯算子是2個維上二階差分的和(見式3.3),其公式為:

image   (3.4)

上式對應的卷積核為

                       image

常用的拉普拉斯核有:

                      image

3.1.2 應用

拉普拉斯算子會突出像素值快速變化的區域,因此常用於邊緣檢測。

 

 

Matlab裡有兩個函數

1)del2

計算公式:image ,image  

2)fspecial:圖像處理中一般利用Matlab函數fspecial

h = fspecial('laplacian', alpha) returns a 3-by-3 filter approximating the shape of the two-dimensional Laplacian operator.
The parameter alpha controls the shape of the Laplacian and must be in the range 0.0 to 1.0. The default value for alpha is 0.2.

 

3.1.3 資源

http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html (非常清晰的Laplacian Operator介紹,本文的主要參考)

http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值