完整word版matlab实现数字图像处理Photoshop小程序.docx
- 文档编号:26282886
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:31
- 大小:1.90MB
完整word版matlab实现数字图像处理Photoshop小程序.docx
《完整word版matlab实现数字图像处理Photoshop小程序.docx》由会员分享,可在线阅读,更多相关《完整word版matlab实现数字图像处理Photoshop小程序.docx(31页珍藏版)》请在冰豆网上搜索。
完整word版matlab实现数字图像处理Photoshop小程序
实验报告
课程名称数字图像处理分院班组
姓名学号日期年月日
程序所实现的功能:
1)图像的读取和保存。
2)设计图形用户界面,让用户能够对图像进行任意的亮度和对比度变化调整,
显示和对比变换前后的图像.
3)设计图形用户界面,让用户能够用鼠标选取图像感兴趣区域,显示和保存该
选择区域.
4))图像直方图均衡,要求显示直方图统计,比较直方图均衡后的效果.
5)能对图像加入各种噪声,并通过几种滤波算法实现去噪并显示结果.
6)底片效果
7)边缘信息
8)图像反转
程序实现的亮点
设计简洁的菜单栏以及常用工具的快捷图标也可以使用对应功能的快捷键,包括新建,打开(CTRL+O),保存(CTRL+S);
菜单栏里更是增加了操作撤销与图像还原的操作,可是实现返回操作.
总体设计
图1
软件的总体设计界面布局如上图所示,主要分为2个部分:
显示区域与操作区域.
显示区域:
显示载入原图,以及通过处理后的图像。
操作区域:
通过功能键实现对图像的各种处理,为了实现界面的简洁,大部分的功能放到了菜单栏里。
在截图中可见,左部为一系列功能按键如“对比度调节”、“亮度调节"、“裁剪”等等;界
面正中部分为图片显示部分,界面中下方为系列功能切换选择组。
菜单栏的设计展示
图2
具体设计
现介绍各个功能模块的功能与实现。
4。
1菜单栏的设计.
通过MenuEditor创建如下菜单,通过以下菜单来控制显示或隐藏功能按键
图3
以“文件”菜单中“打开”为例说明实现用户界面功能键“打开”的显示与隐藏.
实现该功能通过添加callback就可以了:
通过ToolbarEditor可以添加快捷图标,如下图:
图4
图像的读取和保存.
(1)利用“文件"菜单中的“打开”、“保存"或者使用菜单栏下的快捷图标分别实现图片的读取与保存。
图5
如果没有选中文件还会提示
图6
(2)图像保存。
利用“uiputfile”、“imwrite”函数实现图像文件的保存。
图7
同样按下去下取消键会提示:
图8
(3)程序的退出。
你可以在菜单栏使用退出键,或者在主界面右下角有关闭按钮就可以退出程序。
对图像进行任意的亮度和对比度变化调整,显示和对比变换前后的图像。
按下亮度调节按钮会弹出输入框,输入调节倍数,如下图:
图9
(注意:
这里的倍数是相反的调节,你会发现输入0。
1后亮度会变亮)
调节后的图像如下:
图11
对比度的调节跟亮度一样,调节后的图像如下:
图12
4.4用鼠标选取图像感兴趣区域,显示和保存该选择区域.
按下裁剪按钮把鼠标移动到处理后的图像窗口,光标会变成十字形状,拖动光标会出现方框,如下:
图13
双击方框里的图像就完成了裁剪。
4。
5图像转化为灰度图像。
由于在matlab中较多的图像处理函数支持对灰度图像进行处理,故对图像进行灰
度转化十分必要。
可利用rgb2gray(X)函数对其他图像进行灰度图像的转化.
转化实例如下:
图14
4。
8加入各种噪声,并通过几种滤波算法实现去噪.
(1)加入噪声。
通过imnoise(I,type,parameters)来加入各种噪声。
加入椒盐噪声
图15
加入噪声后:
图16
高斯噪声:
乘性噪声:
图17
这几种噪声我加入的参数都是0.02,效果逐渐加深。
滤波:
选择线性滤波的结果如下,可以看出滤去了大部分噪声,(注意:
这几个滤波不可以叠加使用,否则出现白屏)
图17
翻转:
左右翻转
图18
上下翻转:
图19
工具——〉底片效果:
图20
边缘信息:
图21
5、结果分析
软件测试基本成功,课题所要求的功能均能较好实现。
但一些功能只支持灰
度图像的处理。
其中值得一提的是在滤波处理中的低通滤波与高通滤波的效果。
由于一般图
像中含有较多的低频信息成分高频成分较少,通过低通滤波后,噪声以及高频成
分被滤除,图像虽有少量失真,略显模糊,但尚可辨识。
但若是通过高通滤波后,
大量的有效低频信息被滤除,图像严重失真,不可辨识。
源码:
functionduibidu_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinduibidu
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string'SelectionChanged'(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
globalstr
str=get(hObject,’string');
axes(handles.axes2);
switchstr
case'增强'
T=getimage;
prompt={’输入参数:
'};
defans={'1'};
p=inputdlg(prompt,’input',1,defans);
p1=str2double(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=str2double(p{1});
f=imdivide(handles.img,p1);
imshow(f);
handles。
img=f;
guidata(hObject,handles);
end
%-——Executesonbuttonpressinliangdu。
functionliangdu_Callback(hObject,eventdata,handles)
%hObjecthandletoliangdu(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
prompt={'调整倍数’};
defans={’1'};
p=inputdlg(prompt,’input’,1,defans);
p1=str2double(p{1});
y=imadjust(handles.img,[],[],p1);%亮度调节
imshow(y);
handles.img=y;
guidata(hObject,handles);
%——-—-——--————-———-—-———-———--————-————-——-—-—-———-—--——————--—----——
functionwenjian_Callback(hObject,eventdata,handles)
%hObjecthandletowenjian(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%-——--—-----—-—-—-—--—-—-—-—---—---——---—--—--—-——————————-———-—-—-——
functionopen_Callback(hObject,eventdata,handles)
%hObjecthandletoopen(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
[filename,pathname]=uigetfile({’*。
jpg';’*。
bmp';’*。
tif';’*。
*'},'载入图像’);
ifisequal(filename,0)|isequal(pathname,0)
errordlg(’没有选中文件','出错');
return;
else
file=[pathname,filename];
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
%-------———-—-—-—--—---—-—--———-——----—--—————-—-——--———————--—--—-—-
functionsave_Callback(hObject,eventdata,handles)
%hObjecthandletosave(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
[sfilename,sfilepath]=uiputfile({’*.jpg';'*.bmp’;'*.tif’;'*.*’},’保存图像文件','untitled。
jpg');
if~isequal([sfilename,sfilepath],[0,0])
sfilefullname=[sfilepath,sfilename];
imwrite(handles.img,sfilefullname);
else
msgbox(’你按了取消键’,’保存失败’);
end
%--—-————-————-————-----—-———-——-———-———-----——----——-—-—-——--—---—-—
functionexit_Callback(hObject,eventdata,handles)
%hObjecthandletoexit(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
clc;
closeall;
close(gcf);
clear;
%-—---—-———-—-—-—---—-—-——--————--————----—-————---——--——--——---—————
functionIM_Callback(hObject,eventdata,handles)
%hObjecthandletoIM(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%—--—-——--—-———--—-—--—-------—---——------——--—--——————-——--————-----
functionduibidu_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinduibidu
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string’SelectionChanged'(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
globalstr
str=get(hObject,’string');
axes(handles.axes2);
switchstr
case’增强’
T=getimage;
prompt={’输入参数:
’};
defans={’1’};
p=inputdlg(prompt,'input',1,defans);
p1=str2double(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=str2double(p{1});
f=imdivide(handles。
img,p1);
imshow(f);
handles。
img=f;
guidata(hObject,handles);
end
%——-—------—-—----———-—-——--—-—--——---——--——-———---———--—--——----—---
functionhuidu_Callback(hObject,eventdata,handles)
%hObjecthandletohuidu(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
x=rgb2gray(handles.img);
imshow(x);
handles。
img=x;
guidata(hObject,handles);
%--—-—-—-—-—--——--———-——--—---—-——-—--—-——----—--————-—-—————--—----—
functioncaijian_Callback(hObject,eventdata,handles)
%hObjecthandletocaijian(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
x=imcrop(handles。
img);%截图
imshow(x);
handles.img=x;
guidata(hObject,handles);
%—--Executesonbuttonpressinzhifangtu.
functionzhifangtu_Callback(hObject,eventdata,handles)
%hObjecthandletozhifangtu(seeGCBO)
%eventdatareserved—tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
h=histeq(handles。
img);
imshow(h);
handles.img=h;
guidata(hObject,handles);
%——-Executeswhenselectedobjectischangedinuipanel4。
functionuipanel4_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinuipanel4
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string’SelectionChanged’(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%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
%—--Executeswhenselectedobjectischangedinuipanel5.
functionuipanel5_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinuipanel5
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string’SelectionChanged’(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
str=get(hObject,’string’);
axes(handles.axes2);
switchstr
case’中值滤波'
T=getimage;
k=medfilt2(handles。
img);
imshow(k);
handles。
img=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word matlab 实现 数字图像 处理 Photoshop 程序