滤波器设计实验报告-一张图像的各种滤波器的设计与实现.doc_第1页
滤波器设计实验报告-一张图像的各种滤波器的设计与实现.doc_第2页
免费预览已结束,剩余17页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

广东药学院 实验报告 实验九 一张图像的各种滤波器的设计与实现班级: 生物医学工程09 姓名: 学号: 2011年12月21日1实验目的12.实验内容与要求13.实验内容与实验步骤23.1 gui界面的形成:23.2各种滤波器实现代码:43.2.1. 三维转二维43.2.2. 加入椒盐噪声53.2.3 . 图像读入63.2.4. 图像信息查询63.2.5. 进行高斯滤波73.2.6. 进行sobel滤波83.2.7. 进行prewitt滤波93.2.8. 进行拉普拉斯滤波103.2.9. 进行高斯拉普拉斯滤波113.2.10. 进行均值滤波123.2.11. 进行模糊滤波133.2.12. 进行高通高斯滤波143.2.13. 进行中值滤波153.2.14. 彩色图像转灰度图像163.2.15. 灰度图像转为索引图像173.2.16. 图像转为二值图像174.实验心得:181实验目的1学会使用matlab的m文本和gui界面的设计2.学会各种滤波器函数的调用与设计3.对各种滤波器的效果进行对比分析2.实验内容与要求 1、位图格式图像基本操作2、图像的读取3、各种滤波器的实现4、滤波器效果的比较。3.实验内容与实验步骤3.1 gui界面的形成: 实验代码: function varargout = untitled(varargin)% untitled m-file for untitled.fig% untitled, by itself, creates a new untitled or raises the existing% singleton*.% h = untitled returns the handle to a new untitled or the handle to% the existing singleton*.% untitled(callback,hobject,eventdata,handles,.) calls the local% function named callback in untitled.m with the given input arguments.% untitled(property,value,.) creates a new untitled or raises the% existing singleton*. starting from the left, property value pairs are% applied to the gui before untitled_openingfunction gets called. an% unrecognized property name or invalid value makes property application% stop. all inputs are passed to untitled_openingfcn via varargin.% *see gui options on guides tools menu. choose gui allows only one% instance to run (singleton).% see also: guide, guidata, guihandles% edit the above text to modify the response to help untitled% last modified by guide v2.5 13-dec-2011 20:58:27% begin initialization code - do not editgui_singleton = 1;gui_state = struct(gui_name, mfilename, . gui_singleton, gui_singleton, . gui_openingfcn, untitled_openingfcn, . gui_outputfcn, untitled_outputfcn, . gui_layoutfcn, , . gui_callback, );if nargin & isstr(varargin1) gui_state.gui_callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_state, varargin:);else gui_mainfcn(gui_state, varargin:);end% end initialization code - do not edit% - executes just before untitled is made visible.function untitled_openingfcn(hobject, eventdata, handles, varargin)% this function has no output args, see outputfcn.% hobject handle to figure% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)% varargin command line arguments to untitled (see varargin)% choose default command line output for untitledhandles.output = hobject;% update handles structureguidata(hobject, handles);% uiwait makes untitled wait for user response (see uiresume)% uiwait(handles.figure1);% - outputs from this function are returned to the command line.function varargout = untitled_outputfcn(hobject, eventdata, handles)% varargout cell array for returning output args (see varargout);% hobject handle to figure% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)% get default command line output from handles structurevarargout1 = handles.output;界面框图:设计心得:由于对gui界面的不熟悉和设计前没有详细的规划好界面的分布图,所以导致界面设计的不和谐,这给后面的设计也带来了很大的烦恼,在学习界面这方面还要下些功夫。3.2各种滤波器实现代码:3.2.1. 三维转二维% - executes on button press in pushbutton1.function pushbutton1_callback(hobject, eventdata, handles)% hobject handle to pushbutton1 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);g0 = g0(:,:,2); %三维转二维figure(1);imshow(g0) ;title(原图) 效果: 原 图 二维 对比心得:三维图像转二维图像,效果是彩色图变成黑白的,但是黑白的图像不可能还原成原本的彩色图像,只能人为的着色,也就是说不能逆转。3.2.2. 加入椒盐噪声% - executes on button press in pushbutton2.function pushbutton2_callback(hobject, eventdata, handles)% hobject handle to pushbutton2 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);g1=imnoise(g0,salt & pepper,0.2);g1=im2double(g1);figure(2);imshow(g1);title(加入椒盐噪声) 原 图 效果对比心得:百度知识:椒盐噪声是由图像传感器,传输信道,解码处理等产生的黑白相间的亮暗点噪声。椒盐噪声往往由图像切割引起。去除脉冲干扰级椒盐噪声最常用的算法是中值滤波3.2.3 . 图像读入 % - executes on button press in pushbutton3.function pushbutton3_callback(hobject, eventdata, handles)% hobject handle to pushbutton3 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)i=imread (lena.jpg) ; %图像读入figure(11); imshow(i) %图像显示 原 图 效果3.2.4. 图像信息查询% - executes on button press in pushbutton5.function pushbutton5_callback(hobject, eventdata, handles)% hobject handle to pushbutton5 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)inf=imfinfo(lena.jpg) % 图像信息查询3.2.5. 进行高斯滤波% - executes on button press in pushbutton7.function pushbutton7_callback(hobject, eventdata, handles)% hobject handle to pushbutton7 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(g0) g0=rgb2gray(g0)endg1=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滤波% - executes on button press in pushbutton8.function pushbutton8_callback(hobject, eventdata, handles)% hobject handle to pushbutton8 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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滤波是一种边沿检测,百度:sobel算子并没有将图像的主体与背景严格地区分开来,换言之就是sobel算子没有基于图像灰度进行处理,由于sobel算子没有严格地模拟人的视觉生理特征,所以提取的图像轮廓有时并不能令人满意。3.2.7. 进行prewitt滤波% - executes on button press in pushbutton9.function pushbutton9_callback(hobject, eventdata, handles)% hobject handle to pushbutton9 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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. 进行拉普拉斯滤波% - executes on button press in pushbutton10.function pushbutton10_callback(hobject, eventdata, handles)% hobject handle to pushbutton10 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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. 进行高斯拉普拉斯滤波% - executes on button press in pushbutton11.function pushbutton11_callback(hobject, eventdata, handles)% hobject handle to pushbutton11 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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. 进行均值滤波% - executes on button press in pushbutton12.function pushbutton12_callback(hobject, eventdata, handles)% hobject handle to pushbutton12 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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. 进行模糊滤波% - executes on button press in pushbutton13.function pushbutton13_callback(hobject, eventdata, handles)% hobject handle to pushbutton13 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(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. 进行高通高斯滤波% - executes on button press in pushbutton14.function pushbutton14_callback(hobject, eventdata, handles)% hobject handle to pushbutton14 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(g0) g0=rgb2gray(g0)end g1=imnoise(g0,salt & pepper,0.2);g1=im2double(g1);h8=0 -1 0;-1 5 -1;0 -1 0;g9=filter2(h8,g1,same);figure(9);imshow(g9);title(进行高通高斯滤波); 原 图 效果对比心得:同理高通高斯滤波和高斯拉普拉斯滤波的原理差不多,都是把两个滤波器加在一起,但是它的效果比高斯拉普拉斯滤波的好一些。3.2.13. 进行中值滤波% - executes on button press in pushbutton15.function pushbutton15_callback(hobject, eventdata, handles)% hobject handle to pushbutton15 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)g0=imread(lena.tif);if isrgb(g0) g0=rgb2gray(g0)end g1=imnoise(g0,salt & pepper,0.2);g1=im2double(g1);h9=g1;g10=medfilt2(h9);figure(10);imshow(g10);title(进行中值滤波); 原 图 效果 对比心得:中值滤波让图片看起来变得有点平滑柔软的感觉。百度:中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值.3.2.14. 彩色图像转灰度图像% - executes on button press in pushbutton19.function pushbutton19_callback(hobject, eventdata, handles)% hobject handle to pushbutton19 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)i=imread (lena.jpg); x1=rgb2gray(i); figure(12);imshow(x1) 效果心得:灰度图像和黑白图像有一点区别:灰度图像通常显示为从最暗黑色到最亮的白色的灰度,尽管理论上这个采样可以任何颜色的不同深浅,甚至可以是不同亮度上的不同颜色,而黑白图像则是只有黑色与白色两种颜色。3.2.15. 灰度图像转为索引图像% - executes on button press in pushbutton20.function pushbutton20_callback(hobject, eventdata, handles)% hobject handle to pushbutton20 (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see gu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论