《数字图像处理》实验报告三:空间滤波 / Laplacian算子

一、实验任务与要求

  • 对图像进行空间滤波(img1)
  • 使用 Laplacian 算子增强图像(img2)

 

二、实验报告 

(一)对图像进行空间滤波(img1)

 

 

1、空间滤波处理

fspecial():用于生成滤波器(算子)

h=fspecial('type',para); %type:gaussian,average,laplacian,motion……

imfilter():对图像进行滤波处理

g=imfilter(f,w,filtering_mode,boundary_options,size_options);

 

2、实现代码

img1=imread('C:\Users\Lenovo\Desktop\exp3\img1.tif');

h1=fspecial('average',100); %均值滤波器
img11=imfilter(img1,h1,'corr','replicate','same');
h2=fspecial('gaussian',50,1); %低通滤波器
img12=imfilter(img1,h2,'corr','replicate','same');
h3=fspecial('disk',20); %圆盘均值滤波器
img13=imfilter(img1,h3,'corr','replicate','same');
h4=fspecial('motion',200,100); %运动滤波器
img14=imfilter(img1,h4,'corr','replicate','same');
h5=fspecial('laplacian',0.2); %二维Laplacian算子的逼近滤波器
img15=imfilter(img1,h5,'corr','replicate','same');

subplot(3,2,1);
imshow(img1);title('原图');
subplot(3,2,2);
imshow(img11);title('average');
subplot(3,2,3);
imshow(img12);title('gaussian');
subplot(3,2,4);
imshow(img13);title('disk');
subplot(3,2,5);
imshow(img14);title('motion');
subplot(3,2,6);
imshow(img15);title('laplacian');

 

3、效果

 

 

(二)使用Laplacian算子增强图像(img2)

 

 

1、uint8 直接使用 laplacian 滤波处理

img2=imread('C:\Users\Lenovo\Desktop\exp3\img2.tif');
h=fspecial('laplacian',0.2); %拉普拉斯算子
g1=imfilter(img2,h,'corr','replicate','same'); 
imshow(g1);title('uint8 laplacian');

继续锐化: 

img21=img2-2*g1; %锐化1.0
imwrite(img21,'C:\Users\Lenovo\Desktop\exp3\锐化1.0.tif');

效果: 

 

可以看出效果不是很理想,不能直接使用 laplacian 滤波处理。

 

2、先进行类型转换,再使用 laplacian 滤波处理

img2_d=im2double(img2); %将图像转换为double类型
g2=imfilter(img2_d,h,'corr','replicate','same');
img22=img2_d-2*g2; %锐化2.0
imwrite(img22,'C:\Users\Lenovo\Desktop\exp3\锐化2.0.tif');

效果:

可以看出效果好很多。因为原图是一幅 uint8 类图像,输出结果也是 uint8 类,所有像素均为正值,而 laplacian 滤波模板中存在负值,变换结果中的所有负值被截掉,所以需要先进行类型变换,将图像转化为 double 类型再进行滤波处理,得到的锐化效果较为理想。 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值