GUI图像处理要点.docx

上传人:b****7 文档编号:23536698 上传时间:2023-05-18 格式:DOCX 页数:64 大小:4.63MB
下载 相关 举报
GUI图像处理要点.docx_第1页
第1页 / 共64页
GUI图像处理要点.docx_第2页
第2页 / 共64页
GUI图像处理要点.docx_第3页
第3页 / 共64页
GUI图像处理要点.docx_第4页
第4页 / 共64页
GUI图像处理要点.docx_第5页
第5页 / 共64页
点击查看更多>>
下载资源
资源描述

GUI图像处理要点.docx

《GUI图像处理要点.docx》由会员分享,可在线阅读,更多相关《GUI图像处理要点.docx(64页珍藏版)》请在冰豆网上搜索。

GUI图像处理要点.docx

GUI图像处理要点

1、设计目的:

综合运用MATLAB工具箱实现图像处理的GUI程序设计,利用MATLAB图像处理工具箱,设计和实现自己的Photoshop。

2、题目分析

利用matlab的GUI程序设计一个简单实用的图像处理程序。

该程序应具备图像处理的常用功能,以满足用户的使用。

现设计程序有以下基本功能:

1)图像的读取和保存。

2)设计图形用户界面,让用户能够对图像进行任意的亮度和对比度变化调整,显示和对比变换前后的图像。

3)设计图形用户界面,让用户能够用鼠标选取图像感兴趣区域,显示和保存该选择区域。

4)编写程序通过最近邻插值和双线性插值等算法将用户所选取的图像区域进行放大和缩小整数倍的操作,并保存,比较几种插值的效果。

5)图像直方图统计和直方图均衡,要求显示直方图统计,比较直方图均衡后的效果。

6)能对图像加入各种噪声,并通过几种滤波算法实现去噪并显示结果。

7)额外功能。

3、总体设计

图一

软件的总体设计界面布局如上图所示,主要分为2个部分:

显示区域与操作区域。

显示区域:

显示载入原图,以及通过处理后的图像。

操作区域:

通过功能键实现对图像的各种处理。

在截图中可见,左部为一系列功能按键如“还原”、“撤销”、“截图”等等;界面正中部分为图片显示部分,界面中下方为系列功能切换选择组。

设计完成后运行的软件界面如下:

图二

与图一先比,运行后的界面更为简洁。

利用“编辑”菜单可调出相应的功能键。

例如:

4、具体设计

现介绍各个功能模块的功能与实现。

4.1菜单栏的设计。

通过MenuEditor

创建如下菜单,通过以下菜单来控制显示或隐藏功能按键

以“编辑”菜单中“图像变形”中的“图像翻转”为例说明实现用户界面功能键“图像翻转”的显示与隐藏。

实现该功能的程序段如下:

functiontuxiangfanzhuan_Callback(hObject,eventdata,handles)

%hObjecthandletotuxiangfanzhuan(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

set(handles.uipanel7,'Visible','on');

ifstrcmp(get(gcbo,'Checked'),'on')

set(handles.uipanel7,'Visible','on');

set(gcbo,'Checked','off');

set(handles.uipanel7,'Visible','off');

else

set(gcbo,'Checked','on');

end

该段程序通过设置“图像翻转”功能键对应的句柄uipanel7中的“Visible”属性的开关来实现该功能键的显示隐藏。

其他同理。

4.2图像的读取和保存。

(1)利用“文件”菜单中的“打开”、“保存为…”分别实现图片的读取与保存。

利用matlab中“uigetfile”、“imread”“imshow”实现图像文件的读取与显示:

functionopen(hObject,eventdata,handles)

%hObjecthandletoopenfile(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

[]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像');

ifisequal()|isequal(pathname,0)

errordlg('没有选中文件','出错');

return;

else

file=[pathname,];

globalS%设置一个全局变量S,保存初始图像路径,以便之后的还原操作

S=file;

x=imread(file);

set(handles.axes1,'HandleVisibility','ON');

axes(handles.axes1);

imshow(x);

set(handles.axes1,'HandleVisibility','OFF');

axes(handles.axes2);

imshow(x);

handles.img=x;

guidata(hObject,handles);

end

程序关键部分:

通过[]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像')选择相应路径打开的图像;通过file=[pathname,];x=imread(file);读取选中的图像;最后,通过imshow(x)在显示区域上显示图像。

 

(2)图像保存。

利用“uiputfile”、“imwrite”函数实现图像文件的保存。

functionsave_Callback(hObject,eventdata,handles)

%hObjecthandletosave(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

[s,s]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像文件','untitled.jpg');

if~isequal([s],[0,0])

s[s,s];

imwrite(handles.img,s);

else

msgbox('你按了取消键','保存失败');

end

程序关键部分:

通[s,s]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像文件','untitled.jpg')选择图像文件保存的路径与格式;然后,通过s[s,s];

imwrite(handles.img,s);实现对图像的保存。

(3)程序的退出。

functionexit_Callback(hObject,eventdata,handles)

%hObjecthandletoexit(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

clc;

closeall;

close(gcf);

clear;

4.3对图像进行任意的亮度和对比度变化调整,显示和对比变换前后的图像。

运行程序后,通过“编辑”菜单中的“常用处理”选中“亮度调节”

在显示出相应的功能键后,通过载入读取图像,比并进行处理,效果如下:

亮度处理前:

亮度处理后:

实现程序段如下:

%---Executesonbuttonpressinradiobutton12.

functionradiobutton12_Callback(hObject,eventdata,handles)

%hObjecthandletoradiobutton12(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hint:

get(hObject,'Value')returnstogglestateofradiobutton12

globalT

axes(handles.axes2);

T=getimage;

prompt={'调整倍数'};

defans={'1'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

y=imadjust(handles.img,[],[],p1);%亮度调节

imshow(y);

handles.img=y;

guidata(hObject,handles);

 

对比度处理前:

对比度处理后(增强3倍):

对比度减弱1.5倍后:

实现程序段如下:

functionuipanel10_SelectionChangeFcn(hObject,eventdata,handles)

%hObjecthandletouipanel10(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

str=get(hObject,'string');

axes(handles.axes2);

switchstr

case'增强'

T=getimage;

prompt={'输入参数:

'};

defans={'1'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=immultiply(handles.img,p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

case'减弱'

T=getimage;

prompt={'输入参数:

'};

defans={'1'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=imdivide(handles.img,p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

end

该程序段主要通过f=immultiply(handles.img,p1);p=inputdlg(prompt,'input',1,defans);

分别实现图像对比度的增强与减弱。

4.4用鼠标选取图像感兴趣区域,显示和保存该选择区域。

通过imcrop(x)函数来实现对图片某一区域的截取,截取的图片在右框中显示。

结合“保存为…”,可把截图处理后的图片保存在指定路径。

实现程序段如下:

%---Executesonbuttonpressinpushbutton1.

functionpushbutton1_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton1(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

axes(handles.axes2);

T=getimage;

x=imcrop(handles.img);%截图

imshow(x);

handles.img=x;

guidata(hObject,handles);

4.5图像转化为灰度图像。

由于在matlab中较多的图像处理函数支持对灰度图像进行处理,故对图像进行灰度转化十分必要。

可利用rgb2gray(X)函数对其他图像进行灰度图像的转化。

转化实例如下:

实现程序段如下:

%---Executesonbuttonpressinradiobutton16.

functionradiobutton16_Callback(hObject,eventdata,handles)

%hObjecthandletoradiobutton16(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hint:

get(hObject,'Value')returnstogglestateofradiobutton16

globalT

axes(handles.axes2);

T=getimage;

x=rgb2gray(handles.img);%RGBͼÏñת»»Îª»Ò¶ÈͼÏñ

imshow(x);

handles.img=x;

guidata(hObject,handles);

4.6对图像进行放大和缩小整数倍的操作。

通过imresize(X,n,mode)函数对图像X进行放大或者缩小。

N放大缩小倍数,mode为采用的方式。

通过处理后可发现保存的图片的比原图放大了(缩小了)。

实现的程序段如下:

functionuipanel9_SelectionChangeFcn(hObject,eventdata,handles)

%hObjecthandletouipanel9(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

str=get(hObject,'string');

axes(handles.axes2);

switchstr

case'最近邻插值'

T=getimage;

prompt={'输入参数:

'};

defans={'2'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=imresize(handles.img,p1,'nearest');

imshow(f);

handles.img=f;

guidata(hObject,handles);

case'双线性插值'

T=getimage;

prompt={'输入参数:

'};

defans={'1'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=imresize(handles.img,p1,'bilinear');

imshow(f);

handles.img=f;

guidata(hObject,handles);

end

4.7图像直方图统计和直方图均衡。

(1)通过histeq(X)函数实现直方图均衡。

因为此函数只能对灰度图像进行直方图均衡。

故应先将彩图转为灰度图像。

在上一步的基础上对第二幅图进行直方图均衡:

直方图均衡实现程序段如下:

%---Executesonbuttonpressinpushbutton7.

functionpushbutton7_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton7(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

axes(handles.axes2);

T=getimage;

h=histeq(handles.img);

imshow(h);

handles.img=h;

guidata(hObject,handles);

关键部分:

通过h=histeq(handles.img)进行直方图均衡

(2)直方图统计。

通过利用imhist(X)函数来实现直方图统计。

%---Executesonbuttonpressinpushbutton8.

functionpushbutton8_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton8(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

axes(handles.axes2);

x=imhist(handles.img);%直方图统计

x1=x(1:

10:

256);

horz=1:

10:

256;

bar(horz,x1);

axis([0255015000]);

set(handles.axes2,'xtick',0:

50:

255);

set(handles.axes2,'ytick',0:

2000:

15000);

注意:

横纵坐标的范围应选取适当,否则,统计图表有可能超出范围。

4.8加入各种噪声,并通过几种滤波算法实现去噪。

(1)加入噪声。

通过imnoise(I,type,parameters)来加入各种噪声。

加入椒盐噪声

加入高斯噪声:

加入乘性噪声:

实现程序段如下:

functionuipanel4_SelectionChangeFcn(hObject,eventdata,handles)

%hObjecthandletouipanel4(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

str=get(hObject,'string');

axes(handles.axes2);

switchstr

case'椒盐噪声'

T=getimage;

prompt={'数日椒盐噪声参数1:

'};

defans={'0.02'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=imnoise(handles.img,'salt&pepper',p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

case'¸高斯噪声'

T=getimage;

prompt={'输入高斯噪声1:

','输入高斯噪声2'};

defans={'0','0.02'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

p2=str2num(p{2});

f=imnoise(handles.img,'gaussian',p1,p2);

imshow(f);

handles.img=f;

guidata(hObject,handles);

case'乘性噪声'

T=getimage;

prompt={'输入乘性噪声1:

'};

defans={'0.02'};

p=inputdlg(prompt,'input',1,defans);

p1=str2num(p{1});

f=imnoise(handles.img,'speckle',p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

end

(2)滤除噪声(椒盐噪声)。

滤波前

中值滤波后

线性滤波后

自适应滤波后

实现程序段如下:

functionuipanel5_SelectionChangeFcn(hObject,eventdata,handles)%图像滤波

%hObjecthandletouipanel5(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalT

str=get(hObject,'string');

axes(handles.axes2);

switchstr

case'中值滤波'

T=getimage;

k=medfilt2(handles.img);

imshow(k);

handles.img=k;

guidata(hObject,handles);

case'线性滤波'

T=getimage;

h=[111;111;111];

H=h/9;

i=double(handles.img);

k=convn(i,h);

imshow(k,[]);

handles.img=k;

guidata(hObject,handles);

case'自适应滤波'

T=getimage;

k=wiener2(handles.img,[5,5]);

imshow(k);

handles.img=k;

guidata(hObject,handles);

end

低通滤波器滤波后

高通滤波器滤波后

实现程序如下:

%---Executesonbuttonpressinpushbutton14.

functionpushbutton14_Callback(hObject,eventdata,ha

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1