数字图象处理苏二鹏02114030.docx
《数字图象处理苏二鹏02114030.docx》由会员分享,可在线阅读,更多相关《数字图象处理苏二鹏02114030.docx(15页珍藏版)》请在冰豆网上搜索。
数字图象处理苏二鹏02114030
图像处理大作业
1、作业要求
完成MatlabGUI程序,两个显示区域,实现功能:
1)读入灰度或彩色图像,放大缩小显示;
2)完成图像对比度的简单、分段线性变换及非线性变换,并与原图像对比;
2、作业目的
运用MATLAB,完成图像处理功能:
1)图片读入。
2)图片放大缩小。
3)灰度图片分段线性于和非线性变换。
3、作业思路
采用MatlabGUI程序完成,分为以下几个步骤:
1)菜单、界面设计
2)编写函数
3)结合allback与函数
4)调试
5)开关处理
4、作业内容
1)菜单、界面设计
运行后界面如下:
2)代码编写:
functionvarargout=untitled1(varargin)
%UNTITLED1M-fileforuntitled1.fig
%UNTITLED1,byitself,createsanewUNTITLED1orraisestheexisting
%singleton*.
%
%H=UNTITLED1returnsthehandletoanewUNTITLED1orthehandleto
%theexistingsingleton*.
%
%UNTITLED1('Property','Value',...)createsanewUNTITLED1usingthe
%givenpropertyvaluepairs.Unrecognizedpropertiesarepassedvia
%varargintountitled1_OpeningFcn.Thiscallingsyntaxproducesa
%warningwhenthereisanexistingsingleton*.
%
%UNTITLED1('CALLBACK')andUNTITLED1('CALLBACK',hObject,...)callthe
%localfunctionnamedCALLBACKinUNTITLED1.Mwiththegiveninput
%arguments.
%
%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone
%instancetorun(singleton)".
%
%Seealso:
GUIDE,GUIDATA,GUIHANDLES
%Edittheabovetexttomodifytheresponsetohelpuntitled1
%LastModifiedbyGUIDEv2.504-May-201417:
50:
43
%Begininitializationcode-DONOTEDIT
gui_Singleton=1;
gui_State=struct('gui_Name',mfilename,...
'gui_Singleton',gui_Singleton,...
'gui_OpeningFcn',@untitled1_OpeningFcn,...
'gui_OutputFcn',@untitled1_OutputFcn,...
'gui_LayoutFcn',[],...
'gui_Callback',[]);
ifnargin&&ischar(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
ifnargout
[varargout{1:
nargout}]=gui_mainfcn(gui_State,varargin{:
});
else
gui_mainfcn(gui_State,varargin{:
});
end
%Endinitializationcode-DONOTEDIT
%---Executesjustbeforeuntitled1ismadevisible.
functionuntitled1_OpeningFcn(hObject,eventdata,handles,varargin)
%Thisfunctionhasnooutputargs,seeOutputFcn.
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%vararginunrecognizedPropertyName/PropertyValuepairsfromthe
%commandline(seeVARARGIN)
%Choosedefaultcommandlineoutputforuntitled1
handles.output=hObject;
%Updatehandlesstructure
%---Outputsfromthisfunctionarereturnedtothecommandline.
functionvarargout=untitled1_OutputFcn(hObject,eventdata,handles)
%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%Getdefaultcommandlineoutputfromhandlesstructure
varargout{1}=handles.output;
%---Executesonbuttonpressinpushbutton3.
functionpushbutton3_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton3(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%---Executesonbuttonpressinpushbutton4.
functionpushbutton4_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton4(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
functionedit1_Callback(hObject,eventdata,handles)
%hObjecthandletoedit1(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%Hints:
get(hObject,'String')returnscontentsofedit1astext
%str2double(get(hObject,'String'))returnscontentsofedit1asadouble
%---Executesduringobjectcreation,aftersettingallproperties.
functionedit1_CreateFcn(hObject,eventdata,handles)
%hObjecthandletoedit1(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled
%Hint:
editcontrolsusuallyhaveawhitebackgroundonWindows.
%SeeISPCandCOMPUTER.
ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
functionedit2_Callback(hObject,eventdata,handles)
%hObjecthandletoedit2(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%Hints:
get(hObject,'String')returnscontentsofedit2astext
%str2double(get(hObject,'String'))returnscontentsofedit2asadouble
%---Executesduringobjectcreation,aftersettingallproperties.
functionedit2_CreateFcn(hObject,eventdata,handles)
%hObjecthandletoedit2(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled
%Hint:
editcontrolsusuallyhaveawhitebackgroundonWindows.
%SeeISPCandCOMPUTER.
ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%--------------------------------------------------------------------
functionm_gray_Callback(hObject,eventdata,handles)
%hObjecthandletom_gray(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%--------------------------------------------------------------------
functionm_file_open_Callback(hObject,eventdata,handles)
globalx
[filename,pathname]=uigetfile(...
{'*.bmp;*.jpg;*.png;*.jpeg','ImageFiles(*.bmp,*.jpg,*.png,*.jpeg)';...
'*.*','AllFiles(*.*)'},...
'Pickanimage');
ifisequal(filename,0)||isequal(pathname,0),
return;
end
axes(handles.axes_1);
fpath=[pathnamefilename];
img_1=imread(fpath);
x=imread(fpath);
imshow(img_1);
set(handles.m_file_save,'Enable','on');
set(handles.reshape,'Enable','on');
set(handles.gray,'Enable','on');
set(handles.noise,'Enable','on');
set(handles.filter,'Enable','on');
%--------------------------------------------------------------------
functionm_file_save_Callback(hObject,eventdata,handles)
[filename,pathname]=uiputfile({'*.bmp','BMPfiles';'*.jpg;','JPGfiles'},'PickanImage');
ifisequal(filename,0)||isequal(pathname,0)
return;
else
fpath=fullfile(pathname,filename);
end
img_1=getappdata(handles.figure_process,'img_1');
%--------------------------------------------------------------------
functionm_gray_feixianxing_Callback(hObject,eventdata,handles)
globalx
axes(handles.axes_2);
set(handles.axes_2,'HandleVisibility','ON');
y=imadjust(x,[0.2,0.5],[01],0.8);
imshow(y);
set(handles.axes_2,'HandleVisibility','OFF');
%--------------------------------------------------------------------
functionm_gray_fenduan_Callback(hObject,eventdata,handles)
globalx
axes(handles.axes_2);
set(handles.axes_2,'HandleVisibility','ON');
f0=0;g0=0;%?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
f1=20;g1=10;
f2=180;g2=230;
f3=255;g3=255;
r1=(g1-g0)/(f1-f0);
b1=g0-r1*f0;
r2=(g2-g1)/(f2-f1);
b2=g1-r2*f1;
r3=(g3-g2)/(f3-f2);
b3=g2-r3*f2;
[m,n]=size(x);
X2=double(x);
fori=1:
m
forj=1:
n
f=X2(i,j);
g(i,j)=0;
if(f>=f1)&(f<=f2)
g(i,j)=r1*f+b2;
else
if(f>=f2)&(f<=f3)
g(i,j)=r3*f+b3;
end
end
end
end
imshow(mat2gray(g));
set(handles.axes_2,'HandleVisibility','OFF');
%--------------------------------------------------------------------
functionm_file_Callback(hObject,eventdata,handles)
%hObjecthandletom_file(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%--------------------------------------------------------------------
functionm_file_exit_Callback(hObject,eventdata,handles)
%hObjecthandletom_file_exit(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
bChanged=getappdata(handles.figure_process,'bChanged');
bSave=getappdata(handles.figure_process,'bSave');
ifbChanged==true&&bSave==false,
btnName=questdlg('?
¨²?
?
?
?
?
¨¹?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
¡À?
?
?
?
?
?
?
¡À?
?
?
?
?
?
','?
¨¢?
?
','¡À?
?
?
','?
?
¡À?
?
?
','¡À?
?
?
');
switchbtnName,
case'¡À?
?
?
',
feval(@axes_2_menu_save_Callback,handles.axes_2_menu_save,eventdata,handles);
case'?
?
¡À?
?
?
'
end
end
%---Executesduringobjectcreation,aftersettingallproperties.
functionaxes_1_CreateFcn(hObject,eventdata,handles)
%hObjecthandletoaxes_1(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled
%Hint:
placecodeinOpeningFcntopopulateaxes_1
%--------------------------------------------------------------------
functionm_zoom_zoomout_Callback(hObject,eventdata,handles)
%hObjecthandletom_zoom_zoomout(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalx;
axes(handles.axes_2);
set(handles.axes_2,'HandleVisibility','ON');
prompt={'Insertthemultiple:
'};
defans={'5'};
p=inputdlg(prompt,'Insert',1,defans);
p1=str2num(p{1});
y=imresize(x,p1,'nearest');
figure,imshow(y);
set(handles.axes_2,'HandleVisibility','OFF');
%--------------------------------------------------------------------
functionm_zoom_zoomin_Callback(hObject,eventdata,handles)
%hObjecthandletom_zoom_zoomin(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalx;
axes(handles.axes_2);
set(handles.axes_2,'HandleVisibility','ON');
prompt={'Insertthemultiple:
'};
defans={'0.5'};
p=inputdlg(prompt,'Insert',1,defans);
p1=str2num(p{1});