1、 实 验 报 告 课程名称 数字图像处理导论 专业班级 _______________ 姓 名 _______________ 学 号 _______________ 电气与信息学院 和谐 勤奋 求是 创新 实验题目 图像复原实验-空域滤波复原 实验室 DSP室&信号室 实验时间 2015 年 10月 13 日 实验类别 设计 同组人数 2 成 绩
2、 指导教师签字: 一.实验目的 1. 掌握图像滤波的基本定义及目的。 2. 理解空间域滤波的基本原理及方法。 3. 掌握进行图像的空域滤波的方法。 二.实验内容 1. 读出eight.tif这幅图像,给这幅图像分别加入椒盐噪声和高斯噪声后并与前一张图显示在同一图像窗口中。 2. 对加入噪声图像选用不同的平滑(低通)模板做运算,对比不同模板所形成的效果,要求在同一窗口中显示。 3. 使用函数imfilter时,分别采用不同的填充方法(或边界选项,如零填充、’replicate’、’symmetric’、’circular’)进行低通滤波,显示处理后的图像。 4. 运用for循
3、环,将加有椒盐噪声的图像进行10次,20次均值滤波,查看其特点,显示均值处理后的图像(提示:利用fspecial函数的’average’类型生成均值滤波器)。 5. 对加入椒盐噪声的图像分别采用均值滤波法,和中值滤波法对有噪声的图像做处理,要求在同一窗口中显示结果。 6. 自己设计平滑空间滤波器,并将其对噪声图像进行处理,显示处理后的图像。 三.实验具体实现 1. 读出(自己选定.tif)这幅图像,给这幅图像分别加入椒盐噪声和高斯噪声后并与前一张图显示在同一图像窗口中。 I=imread('trees.tif'); subplot(1,3,1) imshow(I); title
4、' Original Image '); J = imnoise(I,'salt & pepper',0.05); %noise density=0.05 subplot(1,3,2) imshow(J); title(' salt & pepper '); K= imnoise(I,'gaussian',0.01,0.01); subplot(1,3,3) imshow(K); title(' gaussian ') 2. 对加入噪声图像选用不同的平滑(低通)模板做运算,对比不同模板所形成的效果,要求在同一窗口中显示。 I=imread('m
5、oon.tif'); H = fspecial('sobel'); subplot(2,2,1) imshow(I); title(' Qriginal Image '); Sobel = imfilter(I,H,'replicate'); subplot(2,2,2) imshow(Sobel); title(' Sobel Image ') H = fspecial('laplacian',0.4); lap = imfilter(I,H,'replicate'); subplot(2,2,3) imshow(lap); title(' Laplacian Im
6、age ') H = fspecial('gaussian',[3 3],0.5); gaussian = imfilter(I,H,'replicate'); subplot(2,2,4) imshow(gaussian); title(' Gaussian Image ') 3. 使用函数imfilter时,分别采用不同的填充方法(或边界选项,如零填充、’replicate’、’symmetric’、’circular’)进行低通滤波,显示处理后的图像。 originalRGB = imread('trees.tif'); subplot(3,2,1) imsho
7、w(originalRGB); title(' Qriginal Image '); h = fspecial('motion', 50, 45); %motion blurred filteredRGB = imfilter(originalRGB, h); subplot(3,2,2) imshow(filteredRGB); title(' Motion Blurred Image '); boundaryReplicateRGB = imfilter(originalRGB, h, 'replicate'); subplot(3,2,3) imshow(bounda
8、ryReplicateRGB); title(' 0-Padding'); boundary0RGB = imfilter(originalRGB, h, 0); subplot(3,2,4) imshow(boundary0RGB); title('Replicate'); boundarysymmetricRGB = imfilter(originalRGB, h, 'symmetric'); subplot(3,2,5) imshow(boundarysymmetricRGB); title(' Symmetric '); boundarycircularRGB =
9、imfilter(originalRGB, h, 'circular'); subplot(3,2,6) imshow(boundarycircularRGB); title(' Circular'); 4. 运用for循环,将加有椒盐噪声的图像进行10次,20次均值滤波,查看其特点,显示均值处理后的图像(提示:利用fspecial函数的’average’类型生成均值滤波器)。 I=imread('kids.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1
10、3,1) imshow(J); title(' salt & pepper Noise'); h=fspecial('average'); %Averaging Filtering J1=imfilter(J,h); for i=1:10 J1=imfilter(J,h); subplot(1,3,2) imshow(J1); title(' 10 Averaging Filtering'); end J2=imfilter(J,h); for i=1:20 J2=imfilter(J,h); subplot(1,3,3) imshow(J2); tit
11、le(' 20 Averaging Filtering'); end 5. 对加入椒盐噪声的图像分别采用均值滤波法,和中值滤波法对有噪声的图像做处理,要求在同一窗口中显示结果。 I=imread('trees.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1,3,1) imshow(J); title(' Original Image '); h=fspecial('average'); %Averaging Filtering J1=imfilter(J,h); subplo
12、t(1,3,2) imshow(J1); title(' Averaging Filtering '); J2=medfilt2(J); %Median Filtering subplot(1,3,3) imshow(J2); title(' Median Filtering '); 6. 自己设计平滑空间滤波器,并将其对噪声图像进行处理,显示处理后的图像。 domain=[0 0 8 0 0; 0 0 8 0 0; 8 8 8 8 8;
13、 0 0 8 0 0; 0 0 8 0 0]; I=imread('trees.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1,2,1) imshow(J); title(' Original Image '); K1= ordfilt2(J,5,domain); subplot(1,2,2) imshow(K1); title(' 5*5 Smoothing Fitered Image');
14、 附录:可能用到的函数和参考结果**************报告里不能用参考结果中的图像 1) 读出eight.tif这幅图像,给这幅图像分别加入椒盐噪声和高斯噪声后并与前一张图显示在同一图像窗口中。 I=imread('cameraman.tif'); subplot(1,3,1) imshow(I); title(' Qriginal Image '); J = imnoise(I,'salt & pepper',0.05); %noise density=0.05 subplot(1,3,2) imshow(J); title('
15、salt & pepper '); K= imnoise(I,'gaussian',0.01,0.01); subplot(1,3,3) imshow(K); title(' gaussian '); 图2.1 初始图像及椒盐噪声图像、高斯噪声污染图 2) 对加入噪声图像选用不同的平滑(低通)模板做运算,对比不同模板所形成的效果,要求在同一窗口中显示。 I=imread('trees.tif'); H = fspecial('sobel'); subplot(2,2,1) imshow(I); title(' Qriginal Image ');
16、 Sobel = imfilter(I,H,'replicate'); subplot(2,2,2) imshow(Sobel); title(' Sobel Image ') H = fspecial('laplacian',0.4); lap = imfilter(I,H,'replicate'); subplot(2,2,3) imshow(lap); title(' Laplacian Image ') H = fspecial('gaussian',[3 3],0.5); gaussian = imfilter(I,H,'replicate'); subplo
17、t(2,2,4) imshow(gaussian); title(' Gaussian Image ') 图2.2 原图像及各类低通滤波处理图像 3) 使用函数imfilter时,分别采用不同的填充方法(或边界选项,如零填充、’replicate’、’symmetric’、’circular’)进行低通滤波,显示处理后的图像。 originalRGB = imread('sedemo_onion.png'); subplot(3,2,1) imshow(originalRGB); title(' Original Image '); h = fsp
18、ecial('motion', 50, 45); %motion blurred filteredRGB = imfilter(originalRGB, h); subplot(3,2,2) imshow(filteredRGB); title(' Motion Blurred Image '); boundaryReplicateRGB = imfilter(originalRGB, h, 'replicate'); subplot(3,2,3) imshow(boundaryReplicateRGB); title(' 0-Padding'); boundary0RGB
19、 = imfilter(originalRGB, h, 0); subplot(3,2,4) imshow(boundary0RGB); title('Replicate'); boundarysymmetricRGB = imfilter(originalRGB, h, 'symmetric'); subplot(3,2,5) imshow(boundarysymmetricRGB); title(' Symmetric '); boundarycircularRGB = imfilter(originalRGB, h, 'circular'); subplot(3,2,6
20、) imshow(boundarycircularRGB); title(' Circular'); 图2.3 原图像及运动模糊图像 图2.4 函数imfilter各填充方式处理图像 4) 运用for循环,将加有椒盐噪声的图像进行10次,20次均值滤波,查看其特点,显示均值处理后的图像。 I=imread('kids.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1,3,1) imshow(J); title(' salt & pepper Noise'); h=fspecial('av
21、erage'); %Averaging Filtering J1=imfilter(J,h); for i=1:10 J1=imfilter(J,h); subplot(1,3,2) imshow(J1); title(' 10 Averaging Filtering'); end J2=imfilter(J,h); for i=1:20 J2=imfilter(J,h); subplot(1,3,3) imshow(J2); title(' 20 Averaging Filtering'); end 图2.5 椒盐噪声污染图像经10次、20次均值滤波
22、图像 由图2.5可得,20次滤波后的效果明显好于10次滤波,但模糊程度也更强。 5) 对加入椒盐噪声的图像分别采用均值滤波法,和中值滤波法对有噪声的图像做处理,要求在同一窗口中显示结果 I=imread('kids.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1,3,1) imshow(J); title(' Original Image '); h=fspecial('average'); %Averaging Filtering J1=imfilter(J,h); subplot(1,3,2
23、) imshow(J1); title(' Averaging Filtering '); J2=medfilt2(J); %Median Filtering subplot(1,3,3) imshow(J2); title(' Median Filtering '); 图2.6 椒盐噪声污染图像及均值、中值滤波图像 从图2.6中可以看出,对于椒盐噪声污染的图像处理,中值滤波效果要明显好于均值滤波。经均值滤波器处理后的图像比均值滤波器中结果图像更加模糊。 6) 设计平滑空间滤波器,并将其对噪声图像进行处理,显示处理后的图像。 d
24、omain=[0 0 8 0 0; 0 0 8 0 0; 8 8 8 8 8; 0 0 8 0 0; 0 0 8 0 0]; I=imread('kids.tif'); J = imnoise(I,'salt & pepper',0.05); subplot(1,2,1) imshow(J); title(' Original Image '); K1= ordfilt2(J,5, domain); subplot(1,2,2) imshow(K1); title(' 5*5 Smoothing Fitered Image'); 图2.7 椒盐噪声污染图像及5*5平滑滤波器掩模 掩模值为w=1/25*[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1] 图2.8 椒盐噪声污染图像及5*5平滑滤波器掩模 掩模值为w= [0 0 8 0 0;0 0 8 0 0;8 8 8 8 8; 0 0 8 0 0;0 0 8 0 0] 16






