圖像銳化(三)

圖像銳化的目的是加強圖像中景物的邊緣和輪廓,突出圖像中的細節或增強被模糊了的細節。

方法三:高斯濾波

% 高斯曲線及其一階二階導數
clear;
a=0;sigma=2;
x=-10:0.0001:10;
figure(1)
y=(1/((sqrt(2*pi))*sigma))*exp(-((x-a).^2)/(2*sigma.^2));
plot(x,y,'b','LineWidth',1.5);
z = diff(y);
figure(2)
plot(z,'b','LineWidth',1.5);
z1 = diff(z);
figure(3)
plot(z1,'b','LineWidth',1.5);

從上圖可以看出,總權值的95%包含在2sigma 的中間範圍內,這個特性使得高斯函數常被用來作爲權值;

 

Log 算子

即H爲高斯函數的二階導

clc;
clear;
src=imread('test.jpg');
src=rgb2gray(src);
src=im2double(src);
figure,subplot(231),imshow(src),title('orgin');

%----- log 算子 -----%
H1=fspecial('log', 7, 1);
R1=imfilter(src,H1);
edge1=abs(R1);
subplot(232),imshow(R1),title('noneedge1');
subplot(233),imshow(edge1),title('absedge1');
afterLog1=src+edge1;
subplot(234),imshow(afterLog1),title('afterLog1');

x=[-3 -2 -1 0 1 2 3];
y=[-3 -2 -1 0 1 2 3];
sigma=1;
for i=1:7
    for j=1:7
        H2(i,j)=1/(pi*sigma.^4)*((x(i)*x(i)+y(j)*y(j))/(2*sigma.^2)-1)*exp(1).^(-(x(i)*x(i)+y(j)*y(j))/(2*sigma.^2));
    end
end
R2=imfilter(src,H2);
edge2=abs(R2);
subplot(235),imshow(edge2),title('absedge2');
afterLog2=src+edge2;
subplot(236),imshow(afterLog2),title('afterLog2');

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章