滤波器设计实验报告.docx
- 文档编号:27669536
- 上传时间:2023-07-03
- 格式:DOCX
- 页数:26
- 大小:468.78KB
滤波器设计实验报告.docx
《滤波器设计实验报告.docx》由会员分享,可在线阅读,更多相关《滤波器设计实验报告.docx(26页珍藏版)》请在冰豆网上搜索。
滤波器设计实验报告
广东药学院
实验报告
实验九一张图像的各种滤波器的设计与实现
班级:
生物医学工程09
姓名:
郑曾永、凌智伟、区荣义
学号:
0907512111、0907512115、0907512113
2011年12月21日
1实验目的1
2.实验内容与要求1
3.实验内容与实验步骤2
3.1GUI界面的形成:
2
3.2各种滤波器实现代码:
4
3.2.1.三维转二维4
3.2.2.加入椒盐噪声5
3.2.3.图像读入6
3.2.4.图像信息查询6
3.2.5.进行高斯滤波7
3.2.6.进行sobel滤波8
3.2.7.进行prewitt滤波9
3.2.8.进行拉普拉斯滤波10
3.2.9.进行高斯拉普拉斯滤波11
3.2.10.进行均值滤波12
3.2.11.进行模糊滤波13
3.2.12.进行高通高斯滤波14
3.2.13.进行中值滤波15
3.2.14.彩色图像转灰度图像16
3.2.15.灰度图像转为索引图像17
3.2.16.图像转为二值图像17
4.实验心得:
18
1实验目的
1学会使用MATLAB的M文本和GUI界面的设计
2.学会各种滤波器函数的调用与设计
3.对各种滤波器的效果进行对比分析
2.实验内容与要求
1、位图格式图像基本操作
2、图像的读取
3、各种滤波器的实现
4、滤波器效果的比较。
3.实验内容与实验步骤
3.1GUI界面的形成:
实验代码:
functionvarargout=untitled(varargin)
%UNTITLEDM-fileforuntitled.fig
%UNTITLED,byitself,createsanewUNTITLEDorraisestheexisting
%singleton*.
%
%H=UNTITLEDreturnsthehandletoanewUNTITLEDorthehandleto
%theexistingsingleton*.
%
%UNTITLED('CALLBACK',hObject,eventData,handles,...)callsthelocal
%functionnamedCALLBACKinUNTITLED.Mwiththegiveninputarguments.
%
%UNTITLED('Property','Value',...)createsanewUNTITLEDorraisesthe
%existingsingleton*.Startingfromtheleft,propertyvaluepairsare
%appliedtotheGUIbeforeuntitled_OpeningFunctiongetscalled.An
%unrecognizedpropertynameorinvalidvaluemakespropertyapplication
%stop.Allinputsarepassedtountitled_OpeningFcnviavarargin.
%
%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone
%instancetorun(singleton)".
%
%Seealso:
GUIDE,GUIDATA,GUIHANDLES
%Edittheabovetexttomodifytheresponsetohelpuntitled
%LastModifiedbyGUIDEv2.513-Dec-201120:
58:
27
%Begininitializationcode-DONOTEDIT
gui_Singleton=1;
gui_State=struct('gui_Name',mfilename,...
'gui_Singleton',gui_Singleton,...
'gui_OpeningFcn',@untitled_OpeningFcn,...
'gui_OutputFcn',@untitled_OutputFcn,...
'gui_LayoutFcn',[],...
'gui_Callback',[]);
ifnargin&isstr(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
ifnargout
[varargout{1:
nargout}]=gui_mainfcn(gui_State,varargin{:
});
else
gui_mainfcn(gui_State,varargin{:
});
end
%Endinitializationcode-DONOTEDIT
%---Executesjustbeforeuntitledismadevisible.
functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)
%Thisfunctionhasnooutputargs,seeOutputFcn.
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%varargincommandlineargumentstountitled(seeVARARGIN)
%Choosedefaultcommandlineoutputforuntitled
handles.output=hObject;
%Updatehandlesstructure
guidata(hObject,handles);
%UIWAITmakesuntitledwaitforuserresponse(seeUIRESUME)
%uiwait(handles.figure1);
%---Outputsfromthisfunctionarereturnedtothecommandline.
functionvarargout=untitled_OutputFcn(hObject,eventdata,handles)
%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%Getdefaultcommandlineoutputfromhandlesstructure
varargout{1}=handles.output;
界面框图:
设计心得:
由于对GUI界面的不熟悉和设计前没有详细的规划好界面的分布图,所以导致界面设计的不和谐,这给后面的设计也带来了很大的烦恼,在学习界面这方面还要下些功夫。
3.2各种滤波器实现代码:
3.2.1.三维转二维
%---Executesonbuttonpressinpushbutton1.
functionpushbutton1_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton1(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
g0=g0(:
:
2);%三维转二维
figure
(1);imshow(g0);title('原图')
效果:
原图二维
对比心得:
三维图像转二维图像,效果是彩色图变成黑白的,但是黑白的图像不可能还原成原本的彩色图像,只能人为的着色,也就是说不能逆转。
3.2.2.加入椒盐噪声
%---Executesonbuttonpressinpushbutton2.
functionpushbutton2_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton2(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
figure
(2);imshow(g1);title('加入椒盐噪声')
原图效果
对比心得:
XX知识:
椒盐噪声是由图像传感器,传输信道,解码处理等产生的黑白相间的亮暗点噪声。
椒盐噪声往往由图像切割引起。
去除脉冲干扰级椒盐噪声最常用的算法是中值滤波
3.2.3.图像读入
%---Executesonbuttonpressinpushbutton3.
functionpushbutton3_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton3(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
I=imread('lena.jpg');%图像读入
figure(11);imshow(I)%图像显示
原图效果
3.2.4.图像信息查询
%---Executesonbuttonpressinpushbutton5.
functionpushbutton5_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton5(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
inf=imfinfo('lena.jpg')%图像信息查询
3.2.5.进行高斯滤波
%---Executesonbuttonpressinpushbutton7.
functionpushbutton7_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton7(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h1=fspecial('gaussian',4,0.3);
g2=filter2(h1,g1,'same');
figure(4);imshow(g2);title('进行高斯滤波')
原图效果
对比心得:
高斯滤波主要的用途是信号的平滑处理,通过对比可以看到效果图的两点像素变得之间的差值边的小了很多,这也是photoship中的高斯模糊的效果的原因。
3.2.6.进行sobel滤波
%---Executesonbuttonpressinpushbutton8.
functionpushbutton8_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton8(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h2=fspecial('sobel')
g3=filter2(h2,g1,'same')
figure(5);imshow(g3);title('进行sobel滤波')
原图效果
对比心得:
通过进行sobel滤波后,图像变得混乱了,主要由于sobel滤波是一种边沿检测,XX:
Sobel算子并没有将图像的主体与背景严格地区分开来,换言之就是Sobel算子没有基于图像灰度进行处理,由于Sobel算子没有严格地模拟人的视觉生理特征,所以提取的图像轮廓有时并不能令人满意。
3.2.7.进行prewitt滤波
%---Executesonbuttonpressinpushbutton9.
functionpushbutton9_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton9(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h3=fspecial('prewitt')
g4=filter2(h3,g1,'same')
figure(6);imshow(g4);title('进行prewitt滤波')
原图效果
对比心得:
prewitt滤波和上面的sobel滤波的效果出不多,因为他们都是边沿检测的算子。
但是仔细观察还是有一点的区别的,sobel滤波的效果的亮度好一点。
3.2.8.进行拉普拉斯滤波
%---Executesonbuttonpressinpushbutton10.
functionpushbutton10_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton10(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h4=fspecial('laplacian',0.5);
g5=filter2(h4,g1,'same');
figure(7);imshow(g5);title('进行拉普拉斯滤波');
原图效果
对比心得:
拉普拉斯滤波比边缘检测的效果好一点。
3.2.9.进行高斯拉普拉斯滤波
%---Executesonbuttonpressinpushbutton11.
functionpushbutton11_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton11(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h5=fspecial('log',4,0.3);
g6=filter2(h5,g1,'same');figure(7);
imshow(g6);title('进行高斯拉普拉斯滤波');
原图效果
对比心得:
通过与高斯滤波和拉普拉斯滤波进行对比,可以看到高斯拉普拉斯滤波是两种滤波的结合效果。
3.2.10.进行均值滤波
%---Executesonbuttonpressinpushbutton12.
functionpushbutton12_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton12(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h6=fspecial('average');
g7=filter2(h6,g1,'same');figure(8);
imshow(g7);title('进行均值滤波');
原图效果
对比心得:
均值滤波与高斯滤波的效果好一点。
3.2.11.进行模糊滤波
%---Executesonbuttonpressinpushbutton13.
functionpushbutton13_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton13(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h7=fspecial('unsharp',0.3);
g8=filter2(h7,g1,'same');
figure(8);imshow(g8);title('进行模糊滤波');
原图效果
对比心得:
模糊滤波总体感觉上是在原图的基础上添加了一些多余的像素,让图像看起来有模糊地感觉。
3.2.12.进行高通高斯滤波
%---Executesonbuttonpressinpushbutton14.
functionpushbutton14_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton14(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
g0=imread('lena.tif');
ifisrgb(g0)
g0=rgb2gray(g0)
end
g1=imnoise(g0,'salt&pepper',0.2);
g1=im2double(g1);
h8=[0-10;-15-1;0-10];
g9=filter2(h8,g1,'same');
figure(9);imshow(g9);title('进行高通高斯滤波');
原图效果
对比心得:
同理高通高斯滤波和高斯拉普拉斯滤波的原理差不多,都是把两个滤波器加在一起,但是它的效果比高斯拉普拉斯滤波的好一些。
3.2.13.进行中值滤波
%---Executesonbuttonpressinpushbutton15.
functionpushbutton15_Callback(h
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 滤波器 设计 实验 报告