版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1. 设计目的3 2. 题目分析3 3. 总体设计 3 4. 具体设计5 5. 结果分析 34 6. 心得体会 34 7. 附录代码36 51 1、设计目的:综合运用MATLA工具箱实现图像处理的 GUI程序设计,禾I用 MATLABS像处理工具箱,设计和实现自己的 Photoshop 。 2、题目分析 利用matlab的GUI程序设计一个简单实用的图像处理程序。该程序应具备 图像处理的常用功能,以满足用户的使用。现设计程序有以下基本功能: 1)图像的读取和保存。 2)设计图形用户界面,让用户能够对图像进行任意的亮度和对比度变化调 整,显示和对比变换前后的图像。 3)设计图形用户界面,让用户能
2、够用鼠标选取图像感兴趣区域,显示和保 存该选择区域。 4)编写程序通过最近邻插值和双线性插值等算法将用户所选取的图像区域 进行放大和缩小整数倍的操作,并保存,比较几种插值的效果。 5)图像直方图统计和直方图均衡,要求显示直方图统计,比较直方图均衡 后的效果。 6)能对图像加入各种噪声,并通过几种滤波算法实现去噪并显示结果。 7)额外功能。 3、总体设计 图一 软件的总体设计界面布局如上图所示, 主要分为2个部分:显示区域与操作 区域。 显示区域:显示载入原图,以及通过处理后的图像。 操作区域:通过功能键实现对图像的各种处理。 在截图中可见,左部为一系列功能按键如“还原”、“撤销”、“截图”等等
3、; 界面正中部分为图片显示部分,界面中下方为系列功能切换选择组。 设计完成后运行的软件界面如下: 图二 与图一先比,运行后的界面更为简洁。 利用“编辑”菜单可调出相应的功能键。例如: 4、具体设计 现介绍各个功能模块的功能与实现。 菜单栏的设计。 通过Menu Editor竺创建如下菜单,通过以下菜单来控制显示或隐藏功能按 以“编辑”菜单中“图像变形”中的“图像翻转”为例说明实现用户界面功 能键“图像翻转”的显示与隐藏。 实现该功能的程序段如下: function tuxia ngfan zhua n_Callback(hObject, eve ntdata, han dies) % hObj
4、ect han dle to tuxia ngfan zhua n (see GCBO) % eve ntdata reserved - to be defi ned in a future versi on of MATLAB % han dies structure with han dies and user data (see GUIDATA) set, Visible , on); if strcmp(get(gcbo, Checked ), on) set,Visible, on); set(gcbo, Checked , off ); set,Visible, off ); el
5、se set(gcbo, Checked , on); end 该段程序通过设置“图像翻转”功能键对应的句柄uipanel7中的“Visible 属性的开关来实现该功能键的显示隐藏。其他同理。 图像的读取和保存。 (1)利用“文件”菜单中的“打开”、“保存为”分别实现图片的 读取与保存 tu xiang ch uli 保存主u 退岀 利用 matlab 中 “ uigetfile ”、“imread ”“imshoW实现图像文件的读 取与显示: function openfile_Callback(hObject, eventdata, handles) % hObject handle to
6、 openfile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) filename,pathname=uigetfile( *.jpg ; *.bmp ; *.tif ; *.* , 载 入图像 ); if isequal(filename,0)|isequal(pathname,0) errordlg( 没有选中文件 , 出错 ); return ; else f
7、ile=pathname,filename; global S %设置一个全局变量S,保存初始图像路径,以便之后的还原 操作 S=file; x=imread(file); set, HandleVisibility , ON ); axes; imshow(x); set, HandleVisibility , OFF ); axes; imshow(x); =x; guidata(hObject,handles); end 程序关键部分: 通过 filename,pathname=uigetfile( *.jpg; *.bmp ; *.tif; *.*, 载入图 像 ) 选择相应路径打开的
8、图像;通过 file=pathname,filename; x=imread(file);读取选中的图像;最后,通过imshow(x)在显示区域上显示图 像。 (2)图像保存。 利用“ uiputfile ”、“ imwrite ”函数实现图像文件的保存。 fun ctio n save_Callback(hObject, eve ntdata, han dies) % hObject han dle to save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles
9、structure with han dles and user data (see GUIDATA) sfilename ,sfilepath=uiputfile(*.jpg; *.bmp ; *tif ; *.*,保 存图像文件,); if isequal(sfilename,sfilepath,O,O) sfilefullname=sfilepath ,sfilename; imwrite,sfilefull name); else msgbox(你按了取消键,保存失败); end 程序关键部分: 通 ,保 sfilename ,sfilepath=uiputfile(*jpg ; *b
10、mp ; *tif 存图像文件,”)选择图像文件保存的路径与格式;然后,通过 sfilefullname=sfilepath ,sfilename; imwrite,sfilefull name);实现对图像的保存。 (3)程序的退出。 function exit_Callback(hObject, eventdata, handles) % hObject han dle to exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles structure with
11、 han dles and user data (see GUIDATA) clc; close all ; close(gcf); clear; 对图像进行任意的亮度和对比度变化调整,显示和对比变换前后的图像 运行程序后,通过“编辑”菜单中的“常用处理”选中“亮度调节 *記度调冇 *对比度 盲方图均衡 直方国蜿计 小 在显示出相应的功能键后,通过载入读取图像,比并进行处理,效果如下: 亮度处理前: 亮度处理后: 实现程序段如下: % - Executes on butt on press in radiobutt on 12. fun ctio n radiobutt on 12_Callb
12、ack(hObject, eve ntdata, han dies) % hObject han dle to radiobutto n12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dies structure with han dies and user data (see GUIDATA) % Hi nt: get(hObject,Value) returns toggle state of radiobutt on12 global T axes; T=geti
13、mage; prompt=调整倍数; defans= 1 ; p=in putdlg(prompt,in put ,1,defa ns); %?度调节 p1=str2 nu m(p1); y=imadjust, , ,p1); imshow(y); =y; guidata(hObject,ha ndles); 对比度处理前: 对比度处理后(增强3倍): 对比度减弱倍后: 实现程序段如下: han dles) fun ctio n uipa nel10_Selectio nCha ngeFc n(hObject,eve ntdata, % hObject handle to uipa nel10
14、 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles structure with han dles and user data (see GUIDATA) global T str=get(hObject,stri ng); axes; switch str case增强 T=getimage; prompt=输入参数:; defans=1 ; p=in putdlg(prompt,in put,1,defa ns); p1= str2 nu m(p1); f=imm
15、ultiply,p1); imshow (f); =f; guidata(hObject,ha ndles); case减弱 T=getimage; prompt=输入参数:; defans=1 ; in put ,1,defa ns); p=in putdlg(prompt, p1=str2 num(p1); f=imdivide,p1); imshow (f); =f; guidata(hObject,ha ndles); end 该程序段主要通过f=immultiply,p1); p=in putdlg(prompt,in put ,1,defa ns); 分别实现图像对比度的增强与减弱
16、。 4 . 4用鼠标选取图像感兴趣区域,显示和保存该选择区域。 通过imcrop(x)函数来实现对图片某一区域的截取,截取的图片在右框中 显示。结合“保存为”,可把截图处理后的图片保存在指定路径。 实现程序段如下: % - Executes on butt on press in pushbutt on1. function pushbutt on 1_Callback(hObject, eve ntdata, han dles) % hObject han dle to pushbutto n1 (see GCBO) % eventdata reserved - to be defined
17、in a future version of MATLAB % han dles structure with han dles and user data (see GUIDATA) global T axes; %截图 T=getimage; x=imcrop; imshow(x); =x; guidata(hObject,ha ndles); 图像转化为灰度图像。 由于在matlab中较多的图像处理函数支持对灰度图像进行处理,故对图像进 行灰度转化十分必要。可利用rgb2gray (X)函数对其他图像进行灰度图像的转 化。 转化实例如下: hi处理能S1理后 实现程序段如下: % - E
18、xecutes on butt on press in radiobutt on 16. fun ctio n radiobutt on 16_Callback(hObject, eve ntdata, han dles) % hObject han dle to radiobutto n16 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles structure with han dles and user data (see GUIDATA) % Hi nt: ge
19、t(hObject,Value) returns toggle state of radiobutt on16 global T axes; T=getimage; x=rgb2gray;%RGB? ? ? x a ? ? ? a ? o ? e i ? imshow(x); =x; guidata(hObject,handles); 对图像进行放大和缩小整数倍的操作。 通过imresize(X ,n, mode)函数对图像X进行放大或者缩小。N放大缩小倍数, mode为米用的方式。 通过处理后可发现保存的图片的比原图放大了(缩小了)。 实现的程序段如下: function uipanel9_
20、SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global T str=get(hObject, string ); axes; switch str case 最近邻插值 T=getimage; prompt=
21、输入参数 : ; defans=2 ; p=inputdlg(prompt,input ,1,defans); p1=str2num(p1); f=imresize,p1,nearest ); imshow(f); =f; guidata(hObject,ha ndles); case双线性插值 T=getimage; prompt= 输入参数:; defans=1 ; p=in putdlg(prompt,in put,1,defa ns); p1=str2 num(p1); f=imresize,p1,bili near ); imshow (f); =f; guidata(hObject
22、,ha ndles); end 图像直方图统计和直方图均衡。 (1)通过histeq (X)函数实现直方图均衡。 因为此函数只能对灰度图像进行直方图均衡。故应先将彩图转为灰度图像 在上一步的基础上对第二幅图进行直方图均衡: 直方图均衡实现程序段如下: % - Executes on butt on press in pushbutt on7. function pushbutt on 7_Callback(hObject, eve ntdata, han dies) % hObject han dle to pushbutto n7 (see GCBO) % eventdata reserve
23、d - to be defined in a future version of MATLAB % han dies structure with han dies and user data (see GUIDATA) global T axes; T=getimage; h=histeq; imshow(h); =h; guidata(hObject,ha ndles); 关键部分:通过h=histeq进行直方图均衡 (2)直方图统计。通过利用imhist(X)函数来实现直方图统计。 % - Executes on butt on press in pushbutt on8. functi
24、on pushbutt on 8_Callback(hObject, eve ntdata, han dies) % hObject han dle to pushbutto n8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dies structure with han dies and user data (see GUIDATA) axes; x=imhist;%直方图统计 x1=x(1:10:256); horz=1:10:256; bar(horz,x1); a
25、xis(0 255 0 15000); set, xtick,0:50:255); set, ytick,0:2000:15000); 注意:横纵坐标的范围应选取适当,否则,统计图表有可能超出范围。 加入各种噪声,并通过几种滤波算法实现去噪。 (1)加入噪声。通过imnoise(l,type,parameters)来加入各种噪声。 加入椒盐噪声 吕卯电Jt 加入高斯噪声: 实现程序段如下: fun ctio n uipa nel4_Selectio nCha ngeFc n(hObject, eve ntdata, han dies) % hObject han dle to uipa nel
26、4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles structure with han dles and user data (see GUIDATA) global T str=get(hObject, stri ng ); axes; switch str case 椒盐噪声 T=getimage; prompt=数日椒盐噪声参数1: ; defans= ” ; p=in putdlg(prompt, in put ,1,defa ns); p1= str2
27、nu m(p1); f=imno ise,salt imshow (f); =f; guidata(hObject,ha ndles); case ?高斯噪声 T=getimage; prompt=输入高斯噪声1:,输入高斯噪声2; defans= O , ; p=in putdlg(prompt,in put ,1,defa ns); p1= str2 nu m(p1); p2=str2 nu m(p2); f=imno ise,gaussia n ,p1,p2); imshow (f); =f; guidata(hObject,ha ndles); case 乘性噪声 T=getimage
28、; prompt=输入乘性噪声1: ; defans=” ; p=in putdlg(prompt,in put ,1,defa ns); p1= str2 nu m(p1); f=imno ise, speckle ,p1); imshow (f); =f; guidata(hObject,ha ndles); end (2)滤除噪声(椒盐噪声) 滤波前 中值滤波后 线性滤波后 自适应滤波后 实现程序段如下: function uipa nel5_Selecti on Cha ngeFc n( hObject, eve ntdata, han dles)%图像滤波 % hObject han
29、 dle to uipa nel5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dles structure with han dles and user data (see GUIDATA) global T str=get(hObject,stri ng); axes; switch str case 中值滤波 T=getimage; k=medfilt2; imshow(k); =k; guidata(hObject,ha ndles); case 线性滤波 T=g
30、etimage; h=1 1 1;1 1 1;1 1 1; H=h/9; i=double; k=c onvn( i,h); imshow(k,); =k; guidata(hObject,ha ndles); case 自适应滤波 T=getimage; k=wie ner2,5,5); imshow(k); =k; guidata(hObject,ha ndles); end 高通滤波器滤波后 实现程序如下: % - Executes on butt on press in pushbutt on 14. function pushbutt on 14_Callback(hObject,
31、eve ntdata, han dies) % hObject han dle to pushbutt on 14 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % han dies structure with han dies and user data (see GUIDATA) axes; yi=; f=doubie(y1); 计算 %数据类型转换,matiab不支持图像的无符号整型的 g=fft2(f); %傅里叶变换 g=fftshift(g); M,N=size(g);
32、%转换数据矩阵 nn=2;汇阶巴特沃斯低通滤波器 d0=50; %截止频率50 m=fix(M/2); n=fix(N/2); for i=1:M %计算低通滤波器传递函数 for j=1:N d=sqrt(i-m)A2+(j-nF2); h=1/(1+*(d/d0)A(2* nn); resuit(i,j)=h*g(i,j); end end % 显示处理后的图像 result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2); imshow(y3); % - Executes on button press in pushbutt
33、on15. 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) axes; x=; f=double(x); k=fft2(f); g=fftshift(k); M,N=size(g);
34、nn=2; d0=25; m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt(i-m)A2+(j-门)八2); % 数据类型转换 % 傅里叶变换 % 转换数据矩阵 %截止频率25 % 计算高通滤波器传递 函数 if d?1?卩? e ? a 50 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt(i-m)A2+(j-nF2); h=1/(1+*(d/d0)A(2* nn);% ? ? ? ? ? 2 - ? + ?卩 Y o _e y result(i,j)=h*g(i,j); end end
35、 result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2); imshow(y3); % ? ? e ?2| aiooil ?1 ? % - 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 v
36、ersion of MATLAB % handles structure with handles and user data (see GUIDATA) axes; x=; f=double(x); k=fft2(f); g=fftshift(k); M,N=size(g); nn=2; d0=25; m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt(i-mF2+(j-nf2); ? i ?2 ?+ if d=d0 h=0; else h=1; end result(i,j)=h*g(i,j); end end result=ifftshi
37、ft(result); y2=ifft2(result); y3=uint8(real(y2); imshow(y3); % e y ? Y a dD 1 x a ? ? % ? id0 o ? 士 ? ? ? % x a ? ? e y ? Y ? ? ? %? ? ? 1 ? l ? e ? a 25 % ? ? e ? ? ? 2 - | d % - Executes on button press in pushbutton16. function pushbutton16_Callback(hObject, eventdata, handles) % hObject handle t
38、o pushbutton16 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global T axes; T=getimage; f=edge, canny ); imshow(f); =f; guidata(hObject,handles); % 退出 function edit_Callback(hObject, eventdata, handles) % hO
39、bject handle to edit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 图像编辑 function tuxiangbianxing_Callback(hObject, eventdata, handles) % hObject handle to tuxiangbianxing (see GCBO) % eventdata reserved -
40、to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 添加噪声 function tianjiazaosheng_Callback(hObject, eventdata, handles) % hObject handle to tianjiazaosheng (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles s
41、tructure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 滤波处理 function lvbochuli_Callback(hObject, eventdata, handles) % hObject handle to lvbo
42、chuli (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 常用处理 function changyongchuli_Callback(hObject, eventdata, handles) % hObject handle to changyongchuli (see GCBO) % eventdata reserved - to be defined in
43、a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 图像处理 function teshuchuli_Callback(hObject, eventdata, handles) % hObject handle to teshuchuli (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and u
44、ser data (see GUIDATA) % 图像翻转 function tuxiangfanzhuan_Callback(hObject, eventdata, handles) % hObject handle to tuxiangfanzhuan (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(g
45、et(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 图像旋转 function tuxiangxuanzhuan_Callback(hObject, eventdata, handles) % hObject handle to tuxiangxuanzhuan (see GCBO) % eventdata reserved - to be defined in a future ve
46、rsion of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 低通滤波处理 function ditonglvbochuli_Callback(hObject, eventdata
47、, handles) % hObject handle to ditonglvbochuli (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visi
48、ble , off ); else set(gcbo, Checked , on ); end % 高通滤波处理 function gaotonglvbochuli_Callback(hObject, eventdata, handles) % hObject handle to gaotonglvbochuli (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set
49、, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 图像滤波处理 function tuxianglvbo_Callback(hObject, eventdata, handles) % hObject handle to tuxianglvbo (see GCBO) % eventdata reserved - to be d
50、efined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 亮度调节 function liangdutiaojie_Callback(
51、hObject, eventdata, handles) % hObject handle to liangdutiaojie (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked ,
52、 off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 灰度图像 function huidutxiang_Callback(hObject, eventdata, handles) % hObject handle to huidutxiang (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA
53、) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 对比度 function duibidu_Callback(hObject, eventdata, handles) % hObject handle to duibidu (see GCBO) % eventdata reserved - to be defined
54、 in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set, Visible , on ); if strcmp(get(gcbo, Checked ), on ) set, Visible , on ); set(gcbo, Checked , off ); set, Visible , off ); else set(gcbo, Checked , on ); end % 直方图均衡 function zhifangtujunheng_Callback(hObject, eventdata, handles) % hObject handle to zhifangtujunheng (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure w
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 机动车环保考试试题及答案
- 风电场运维巡检方案
- 船台总装验收管理方案
- 哭泣的河流试题及答案
- 抽水蓄能电站电缆敷设方案
- 城市污水处理厂能力提升深度处理方案
- 地下管网更新改造项目可行性研究报告
- 厨余垃圾资源化处理项目施工方案
- 数据可视化VR技术课程设计
- 《构网型独立储能电站性能测试管理方案》
- 幸福的教师培训课件
- 【《基于SOR模型的电商直播对消费者购物行为的影响实证研究》17000字(论文)】
- 有限空间作业应急预案及现场处置方案
- 城市书店品牌建设
- 6.1认识经济全球化课件-2025-2026学年高中政治统编版选择性必修一当代国际政治与经济
- 2025年国资央企答题题库及答案
- 烫金工艺流程及材料选用指南
- 大观楼景点介绍
- T-CNAS 51-2025 成人患者医用粘胶相关性皮肤损伤的预防及护理
- 实木家具喷漆工艺流程
- 医院后勤安全知识培训课件
评论
0/150
提交评论