数字图像处理课程设计_第1页
数字图像处理课程设计_第2页
数字图像处理课程设计_第3页
数字图像处理课程设计_第4页
数字图像处理课程设计_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

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

文档简介

1、青 岛 科 技 大 学数字图像处理课程设计报告基于GUI的数字图像处理系统设计题 目 _张淑军*指导教师_*学生姓名_学生学号_*信息工程信息与科学技术_院(部)_专业_班_2014_年 _07_月 _10_日411.目的与要求1.进一步巩固数字图像处理中的基本原理与方法,提高分析问题、解决问题的能力。2.熟练掌握一门计算机语言,可以进行数字图像应用处理的开发设计。3.将实验1至实验8所设计的数字图像处理的算法和功能添加到同一个MFC程序中(可以是基于对话框的程序,或者基于单/多文档的程序),形成一个基于MFC的图像处理系统,可以增加一些课本上没有讲到的效果,如风格化等,开发的结果是类似PS的

2、一款软件。4.要求:用户可设置具体参数,可以通过该平台展现不同参数下的实验效果。2.主要技术和原理3.总体方案设计3.1 开发环境和工具PC window7 matlab7.03.2 功能模块图软件的总体设计界面布局如上图所示,两个窗口分别显示源图像和处理后的图像。为了使界面简单明了,通过Menu Editor创建如下菜单,通过上图菜单来控制显示或隐藏功能按键。注:3X3万能模板为新加内容。可实现各种模板滤波。以下截图未做更改。3.3设计步骤和过程等1. 根据课设题目的要求,分析要实现的功能。设计总体的界面。2. 图像的读取,保存和重新加载。3.图像直方图统计和直方图均衡,要求显示直方图统计,

3、比较直方图均衡后的效果。4.设计各种空域滤波器如:均值滤波,中值滤波,Sobel ,Prewitt等。5.能对图像加入各种噪声,并通过几种滤波算法实现去噪并显示结果。 6.频域的高斯低通滤波器和高通滤波器。7.实现图像翻转的功能。4.实验结果与分析4.1图像的读取和保存。 (1)图像的读取 function m_file_open_Callback(hObject, eventdata, handles)% hObject handle to m_file_open (see GCBO)% eventdata reserved - to be defined in a future versi

4、on of MATLAB% handles structure with handles and user data (see GUIDATA)filename,pathname=uigetfile(*.jpg;*.bmp;*.tif;*.*,choose the picture);if isequal(filename,0)|isequal(pathname,0) errordlg(error, again); return;else file=pathname,filename; global S global I S=file; I=imread(file); axes(handles.

5、axes1); imshow(I); handles.img=I; guidata(hObject,handles); End程序关键部分: 通过filename,pathname=uigetfile(*.jpg;*.bmp;*.tif;*.*,载入图像)选择相应路径打开的图像;通过file=pathname,filename; x=imread(file); 读取选中的图像;最后,通过imshow(x)在显示区域上显示图像。(2)图像保存 function m_file_save_Callback(hObject, eventdata, handles)% hObject handle to

6、 m_file_save (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)sfilename ,sfilepath=uiputfile(*.jpg;*.bmp;*.tif;*.*,save the picture,untitled.jpg); if isequal(sfilename,sfilepath,0,0) sfilefullname=sfilepath ,sfile

7、name; imwrite(handles.img,sfilefullname); else msgbox(error,again); End 程序关键部分:通sfilename ,sfilepath=uiputfile(*.jpg;*.bmp;*.tif;*.*,saveThe picture,untitled.jpg)选择图像文件保存的路径与格式;然后,通过sfilefullname=sfilepath ,sfilename;imwrite(handles.img,sfilefullname); 实现对图像的保存。4.2 图像的点操作(1) 直方图增强对比度 function m_file

8、_zhifangtu_Callback(hObject, eventdata, handles)% hObject handle to m_file_zhifangtu (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; g1=T(:,:,1);g2=T(:,:,2); g3=T(:,:,3); g1=histeq(g1); g1=histeq(g1)

9、; g1=histeq(g1); g(:,:,1)=g1; g(:,:,2)=g2; g(:,:,3)=g3; axes(handles.axes2); imshow(g); handles.img=g; guidata(hObject,handles); 程序关键部分: 把彩色图像的三个通道分别加以处理 g1=T(:,:,1),g1=histeq(g1),然后再把处理后的图像合并g(:,:,1)=g1。 J=histeq(I,n) 指定均衡化后的灰度级数 n ,缺省值为 64;(2)显示直方图 function m_file_xianshizhi_Callback(hObject, even

10、tdata, handles)% hObject handle to m_file_xianshizhi (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global I T=getimage; zf=rgb2gray(T); axes(handles.axes2); %axes imhist(zf) handles.img=I; guidata(hObject,handl

11、es);程序关键部分:首先把彩色图转化为会灰度图,然后用imhist()函数显示直方图。imhist(I,n) 其中,n 为指定的灰度级数目,缺省值为256;imhist(X,map) 就算和显示索引色图像 X 的直方图,map 为调色板。用stem(x,counts) 同样可以显示直方图。4.3 图像的模板操作(1) 均值滤波器 function m_file_junyunlubo_Callback(hObject, eventdata, handles)% hObject handle to m_file_junyunlubo (see GCBO)% eventdata reserved

12、- to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; J=imfilter(T,(fspecial(average,3,3); axes(handles.axes2); imshow(J); handles.img=T; guidata(hObject,handles);程序关键部分:此段程序主要调用这个两个函数:(1)B=imfilter(A,h),将原始图像 A 按指定的滤波器 h 进行滤波增强处理,增强后的图

13、像 B 与 A 的尺寸和类型相同。(2)H=fspecial(average,n), 均值滤波器。 (2)二维拉普拉斯运算滤波器function m_file_laplacian_Callback(hObject, eventdata, handles)% hObject handle to m_file_laplacian (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

14、 T=getimage; J=imfilter(T,fspecial(laplacian); axes(handles.axes2); imshow(J); handles.img=T; guidata(hObject,handles);程序关键部分:此段程序主要调用这个两个函数:(1)B=imfilter(A,h),将原始图像 A 按指定的滤波器 h 进行滤波增强处理,增强后的图像 B 与 A 的尺寸和类型相同。(2)H=fspecial(laplacian,alpha) 近似二维拉普拉斯运算滤波器(3)Sobel 水平边缘增强滤波器function m_file_So_Callback(h

15、Object, eventdata, handles)% hObject handle to m_file_So (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; J=imfilter(T,fspecial(sobel); axes(handles.axes2); imshow(J); handles.img=T; guidata(hObject,h

16、andles);程序关键部分:此段程序主要调用这个两个函数:(1)B=imfilter(A,h),将原始图像 A 按指定的滤波器 h 进行滤波增强处理,增强后的图像 B 与 A 的尺寸和类型相同。(2)H=fspecial(sobel) Sobel 水平边缘增强滤波器(4)Prewitt 水平边缘增强滤波器 function m_file_Pre_Callback(hObject, eventdata, handles)% hObject handle to m_file_Pre (see GCBO)% eventdata reserved - to be defined in a futur

17、e version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; J=imfilter(T,fspecial(prewitt); axes(handles.axes2);imshow(J); handles.img=T; guidata(hObject,handles);程序关键部分:此段程序主要调用这个两个函数:(1)B=imfilter(A,h),将原始图像 A 按指定的滤波器 h 进行滤波增强处理,增强后的图像 B 与 A 的尺寸和类型相同。(2)H=fspecial(p

18、rewitt)Prewitt 水平边缘增强滤波器(5)中值滤波器 function m_file_zhongzhi_Callback(hObject, eventdata, handles)% hObject handle to m_file_zhongzhi (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; g1=medfilt2(T(:,:,1)

19、; g2=medfilt2(T(:,:,2); g3=medfilt2(T(:,:,3); g(:,:,1)=g1; g(:,:,2)=g2; g(:,:,3)=g3; axes(handles.axes2); imshow(g); handles.img=T; guidata(hObject,handles); 程序关键部分: 把彩色图像的三个通道分别加以处理 g1=medfilt2(T(:,:,1),然后再把处理后的图像合并g(:,:,1)=g1。medfilt2()中值滤波器4.4添加噪声(1) 椒盐噪声 function m_file_jiaoyan_Callback(hObject,

20、 eventdata, handles)% hObject handle to m_file_jiaoyan (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global TT=getimage;prompt=椒盐噪声参数:; defans=0; p=inputdlg(prompt,input,1,defans); p1=str2num(p1); J=imnoise(T,s

21、alt & pepper,p1); axes(handles.axes1); imshow(J); handles.img=J; guidata(hObject,handles);(2)均匀噪声 function m_file_junyun_Callback(hObject, eventdata, handles)% hObject handle to m_file_junyun (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles

22、 and user data (see GUIDATA) global T T=getimage; prompt=均匀噪声1:; defans=0.02; p=inputdlg(prompt,input,1,defans); p1=str2num(p1); J=imnoise(T,speckle,p1); axes(handles.axes1); imshow(J); handles.img=J; guidata(hObject,handles);(3)高斯噪声 function m_file_gaosi_Callback(hObject, eventdata, handles)% hObje

23、ct handle to m_file_gaosi (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) global T T=getimage; prompt=输入高斯噪声1:,输入高斯噪声2; defans=0,0.02; p=inputdlg(prompt,input,1,defans); p1=str2num(p1); p2=str2num(p2); J=imnoise

24、(T,gaussian,p1,p2); axes(handles.axes1); imshow(J); handles.img=J; guidata(hObject,handles); 程序关键部分:加入噪声。通过imnoise(I,type,parameters)来加入各种噪声。imnoise(I,type) 返回对图像 I 添加典型噪声后的有噪图像 J ,参数 type 和 parameter 用于确定噪声的类型和相应的参数。4.5图像的频域操作(1) 巴特沃斯低通滤波器 function m_file_ditong_Callback(hObject, eventdata, handles

25、)% hObject handle to m_file_ditong (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) T=getimage; prompt=低通滤波器截止频率:; defans=0.2; p=inputdlg(prompt,input,1,defans); p1=str2num(p1); m n=size(T); for i=1:3 A=T(:,:,i);

26、 for j=1:m B=A(j,:); C=double(B); M,N=butter(8,0.1); D=filter(M,N,C); A(j,:)=D; end T(:,:,i)=A; end axes(handles.axes2); imshow(T); handles.img=T; guidata(hObject,handles);(2) 巴特沃斯高通滤波器 function m_file_gaotong_Callback(hObject, eventdata, handles)% hObject handle to m_file_gaotong (see GCBO)% eventd

27、ata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)T=getimage;prompt=高通滤波器截止频率:;defans=0.05;p=inputdlg(prompt,input,1,defans);p1=str2num(p1);m n=size(T);for i=1:3A=T(:,:,i); for j=1:mB=A(j,:);C=double(B);M,N=butter(8,0.1,high);D=filt

28、er(M,N,C);A(j,:)=D;endT(:,:,i)=A;end axes(handles.axes2); imshow(T); handles.img=T; guidata(hObject,handles); 程序关键部分:把彩色图像的三个通道分别处理在合并。利用系统提供的巴特沃斯滤波器M,N=butter(n,wn,high/low),n为滤波器的阶数,wn为截止频率,high/low:高通/低通。D=filter(M,N,C)滤波。对于 D=filter(M,N,C) 使用矩阵MN 中的二维 FIR 滤波器对数据C 进行滤波。4.6 图像变形 (1) 水平翻转 function

29、m_file_zuoyou_Callback(hObject, eventdata, handles)% hObject handle to m_file_zuoyou (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) global T T=getimage; g1=T(:,:,1); g2=T(:,:,2); g3=(T(:,:,3); g1=fliplr(g1); g2

30、=fliplr(g2); g3=fliplr(g3); g(:,:,1)=g1; g(:,:,2)=g2; g(:,:,3)=g3; axes(handles.axes2); imshow(g) ; (2)上下翻转 function m_file_shangxia_Callback(hObject, eventdata, handles)% hObject handle to m_file_shangxia (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB %handles structu

31、re with handles and user data (see GUIDATA)global TT=getimage; g1=T(:,:,1);g2=T(:,:,2);g3=T(:,:,3);g1=flipud(g1);g2=flipud(g2);g3=flipud(g3);g(:,:,1)=g1;g(:,:,2)=g2;g(:,:,3)=g3;axes(handles.axes2);imshow(g) ; 程序关键部分:上下翻转与水平翻转类似,上下翻转函数flipud(),水平翻转函数 fliplr()把彩色图像的三个通道分别处理在合并。(3)任意角度旋转 function m_fil

32、e_fanzhuan_Callback(hObject, eventdata, handles)% hObject handle to m_file_fanzhuan (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage;prompt=xuanzhauanjiaodu:;defans=0;p=input

33、dlg(prompt,input,1,defans);p1=str2num(p1);f=imrotate(T,p1,bilinear,crop);imshow(f);handles.img=f;guidata(hObject,handles); 程序关键部分:f=imrotate(T,p1,bilinear,crop)实现任意角翻转。p1输入的旋转角度,bilinear: 双线性插值(Bilinear interpolation),crop: 通过对旋转后的图像进行裁剪, 保持旋转后输出图像B的尺寸和输入图像A的尺寸一样。 4.7 图像灰度化 function m_file_huidutu_C

34、allback(hObject, eventdata, handles)% hObject handle to m_file_huidutu (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global IJ=rgb2gray(I);axes(handles.axes2); imshow(J); handles.img=J;guidata(hObject,handles);

35、 程序关键部分:J=rgb2gray(I)将彩色图I转化为灰度图J。5.总结与体会通过为期一周的数字图像课程设计实践,使我对图像的处理有了进一步的了解和认识。 当我第一次拿到此次的课题时,感到有些无所适从。虽然,曾经学习过数字图像处理的课程,但由于对图像处理的学习更多的只是停留在理论上的学习,在课时内的试验也只是简单的基础性试验, 所以图像处理的综合运用不是很熟练。虽然对课题感到很懵懂,但在我翻阅有关书籍和上网学习后,我开始找到了解决问题的路径。我选择用matlab的GUI程序设计一个简单实用的图像处理程序。重点是句柄的使用、GUI的使用以及matlab中相关图像处理函数使用。 为此,在实践正

36、式开始前,我利用课余时间,专门借阅了利用matlab进行图像处理的相关教程,通过索引网络上的相关资料,为课设做了较为充分的准备。在参考了相关材料及源程序,我对自己要做的课设内容有了进一步的了解,并对数字图像处理的使用有了更深的体会。当然,在课设的进行过程中,我还是遇到了不少问题。例如,起初由于我对句柄使用以及一些函数使用的不恰当,使得在对图像文件的保存上就遇到了问题,不过最后我通过反复调试把问题解决了。 但是,总体来说,此次的课程设计,还是较为满意的。它不但使我去巩固课上所学的基础理论知识,还提高了我对matlab的实际操作运用,使得理论与实践相结合,为进一步学习数字图像处理打下坚实的基础;同

37、时,在实践的工程中,也让我体会到一种努力付出并得到回报的满足感觉。 参考文献1 唐向宏、岳恒立、郑雪峰等,MATLAB及在电子信息课程中的应用,2009,电子工业出版社2 章毓晋,图像处理和分析教程,2009,人民邮电出版社function varargout = tuxiang(varargin)% TUXIANG M-file for tuxiang.fig% TUXIANG, by itself, creates a new TUXIANG or raises the existing% singleton*.% H = TUXIANG returns the handle to a n

38、ew TUXIANG or the handle to% the existing singleton*.% TUXIANG(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in TUXIANG.M with the given input arguments.% TUXIANG(Property,Value,.) creates a new TUXIANG or raises the% existing singleton*. Starting from the left, prop

39、erty value pairs are% applied to the GUI before tuxiang_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to tuxiang_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instanc

40、e to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES% Copyright 2002-2003 The MathWorks, Inc.% Edit the above text to modify the response to help tuxiang% Last Modified by GUIDE v2.5 14-Jul-2014 10:39:26% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mf

41、ilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, tuxiang_OpeningFcn, . gui_OutputFcn, tuxiang_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else

42、 gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before tuxiang is made visible.function tuxiang_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be def

43、ined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to tuxiang (see VARARGIN)% Choose default command line output for tuxianghandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes tuxiang

44、 wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = tuxiang_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata r

45、eserved - 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;% - Executes on button press in pushbutton1.function edit1_Callback(hObject, eventdata, handles)% hObje

46、ct handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of edit1 as text% str2double(get(hObject,String) returns contents of edit1 as a double% - Executes

47、during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls

48、 usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to

49、be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of edit2 as text% str2double(get(hObject,String) returns contents of edit2 as a double% - Executes during object creation, after setting all properties.fu

50、nction edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,BackgroundColor,white);else set(hObject,Backgro

温馨提示

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

评论

0/150

提交评论