Matlab的图形处理(2)
一、实验名称:
Matlab的图形处理(2)
二、实验目的:
掌握Matlab图形处理的高级技术和方法,熟悉Matlab图像窗口菜单,熟悉Matlab图形用户界面(GUI)设计
三、实验内容及结果:
1、绘制winter色系的三原色。
>> rgbplot(winter(3))
2、由磁盘读入一幅图像(格式任意),并在MATLAB中显示图像。
>>
A=imread('haibianfenjing(6)','jpeg');
>>size(A)
ans =
768 1024 3
>>image(A)
3、在xy坐标,绘制y=2x+8的图像,x的范围[0,10],并求当前图形窗口对象的句柄,当前坐标系的句柄。
>>
x=0:0.01:10;y=2*x+8;plot(x,y)
>> h1=gcf
h1 =
1
>> h2=gca
h2 =
101.0005
4、熟悉图形窗口的菜单:【File】菜单、【Edit】菜单、【View】菜单、【Insert】菜单、【Tools】菜单、【Window】菜单、【Help】菜单。并对其中的选项进行操作,熟悉图像窗口的工具栏操作。
5、利用GUI向导编辑器(GUIDE),完成简单的图形界面设计。要求添加菜单“My first
menu”,添加文本框控件,在文本框控件上显示“My first GUI”,并查看界面的运行结果。
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or
raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle
to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in UNTITLED.M with the given input
arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises
the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before untitled_OpeningFunction gets
called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to
untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose
"GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help
untitled
% Last Modified by GUIDE v2.5 10-Apr-2009 09:57:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State =
struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
%
hObject handle to figure
% eventdata reserved - to be defined in a
future version of MATLAB
%
handles structure with handles and user data (see GUIDATA)
% varargin command line
arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see
UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
function varargout = untitled_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output
args (see VARARGOUT);
%
hObject handle to figure
% eventdata reserved - 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
structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all
properties.
function popupmenu1_CreateFcn(hObject, eventdata,
handles)
%
hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
%
handles empty
- handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata,
handles)
%
hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
%
handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1
contents as cell array
% contents{get(hObject,'Value')} returns selected item from
popupmenu1
% --- Executes 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 usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit1_Callback(hObject, eventdata, handles)
%
hObject 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
五,试验感想和体会:
通过本次实验基本掌握了Matlab图形处理的高级技术和方法,熟悉了Matlab图像窗口菜单,熟悉了Matlab图形用户界面(GUI)设计。
在进行绘制winter色系的三原色时,输入rgbplot(winter(3))和rgbplot(winter(80))是同样的效果,括号里可以随便定义。
在做第二题时由磁盘读入一幅图像,要注意格式盒图像的格式相一致,而且要把图片存在C:\MATLAB6p5\work里,不然找不到指定的图片。
Matlab图形窗口的菜单:【File】菜单、【Edit】菜单、【View】菜单、【Insert】菜单、【Tools】菜单、【Window】菜单、【Help】菜单有很强的功能,熟悉了图像窗口的工具栏操作也很方便。