- 实验内容
(1)任意选择一副灰度图像,使用拉普拉斯算子对图像进行锐化滤波,并和原
图像叠加,实现对图像的增强。
(2)任意选择一副图像,使用 sobel 算子对图像进行锐化滤波,观察滤波效果。
(3)任意选择一副图像,构造一个中心系数为-24 的 5×5 的类似于拉普拉斯模板对图像进行锐化,与中心系数为-8 的 3×3 拉普拉斯算子的结果相比,是否能得到更加清晰的结果?
- 源程序和结果
A=imread('lena.bmp');
A=rgb2gray(A);
h1=fspecial('laplacian'); %拉普拉斯算子,模板默认大小为3*3
h2=fspecial('sobel'); %sobel算子,模板默认大小为3*3
h3=zeros(5,5); %构造模板大小规格为5*5
for i=1:5
for j=1:5
if(i==3&&j==3)
h3(i,j)=-24; %模板中间元素为-24
else
h3(i,j)=1; %模板其它元素为1
end
end
end
h4=zeros(3,3); %构造模板大小规格为3*3
for i=1:3
for j=1:3
if(i==2&&j==2)
h4(i,j)=-8; %模板中间元素为-8
else
h4(i,j)=1; %模板其它元素为1
end
end
end
A1=imfilter(A,h1);
A2=imfilter(A,h2);
A3=imfilter(A,h3);
A4=imfilter(A,h4);
figure(2);
subplot(1,2,1);imshow(A);title('原图');
subplot(1,2,2);imshow(A2);title('sobel3*3');
hold on;
figure(3);
subplot(2,2,1);imshow(A);title('原图');
subplot(2,2,2);imshow(A1);title('原图laplacian3*3');
subplot(2,2,3);imshow(A3);title('原图laplacian5*5(中心系数为-24)');
subplot(2,2,4);imshow(A4);title('原图laplacian3*3*(中心系数为-8)');
B=double(A)/256;B1=double(A1)/256;C=imadd(B,B1);
hold on;
figure(1);
subplot(1,3,1);imshow(A);title('原图');
subplot(1,3,2);imshow(A1);title('拉普拉斯');
subplot(1,3,3);imshow(C,[]);title('叠加');