www.gusucode.com > 用于图像处理的图形用户界面,可实现图像的翻转、加噪、边缘提取等功能 > 用于图像处理的图形用户界面,可实现图像的翻转、加噪、边缘提取等功能/imageshow.m
function varargout = imageshow(varargin) % IMAGESHOW M-file for imageshow.fig % IMAGESHOW, by itself, creates a new IMAGESHOW or raises the existing % singleton*. % % H = IMAGESHOW returns the handle to a new IMAGESHOW or the handle to % the existing singleton*. % % IMAGESHOW('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in IMAGESHOW.M with the given input arguments. % % IMAGESHOW('Property','Value',...) creates a new IMAGESHOW or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before imageshow_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to imageshow_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 % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help imageshow % Last Modified by GUIDE v2.5 27-Nov-2008 17:41:49 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @imageshow_OpeningFcn, ... 'gui_OutputFcn', @imageshow_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(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 imageshow is made visible. function imageshow_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 imageshow (see VARARGIN) [handles.original,handles.map] = imread('moon.tif'); %数据的初始化 handles.image = handles.original; imshow(handles.image,handles.map); % Choose default command line output for imageshow handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes imageshow wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = imageshow_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 on button press in original. function original_Callback(hObject, eventdata, handles) % hObject handle to original (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) imshow(handles.original,handles.map); %显示原图片 % --- Executes on button press in edge. function edge_Callback(hObject, eventdata, handles) % hObject handle to edge (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) BW = edge(handles.image,'sobel'); %边缘检测,采用sobel算子 imshow(BW); % --- Executes on button press in noise. function noise_Callback(hObject, eventdata, handles) % hObject handle to noise (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) noise = imnoise(handles.image,'gaussian'); %添加高斯噪音 imshow(noise,handles.map); % --- Executes on button press in fliplr. function fliplr_Callback(hObject, eventdata, handles) % hObject handle to fliplr (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.image = fliplr(handles.image); %翻转矩阵,使图片水平翻转 imshow(handles.image,handles.map); guidata(hObject,handles); %将翻转后的矩阵记录,并更新到handles.image % --- Executes on selection change in select. function select_Callback(hObject, eventdata, handles) % hObject handle to select (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 select contents as cell array % contents{get(hObject,'Value')} returns selected item from select val = get(hObject,'Value'); str = get(hObject,'String'); switch str{val} %通过switch分支选择,打开不同的文件 case 'moon' [handles.original,handles.map]=imread('moon.tif'); handles.image = handles.original; case 'tree' [handles.original,handles.map]=imread('trees.tif'); handles.image = handles.original; case 'rice' [handles.original,handles.map]=imread('rice.png'); handles.image = handles.original; end guidata(hObject,handles);%更新handles % --- Executes during object creation, after setting all properties. function select_CreateFcn(hObject, eventdata, handles) % hObject handle to select (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