⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.m

📁 A matlab gui for basic image processing operations
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = main(varargin)% MAIN M-file for main.fig%      MAIN, by itself, creates a new MAIN or raises the existing%      singleton*.%%      H = MAIN returns the handle to a new MAIN or the handle to%      the existing singleton*.%%      MAIN('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in MAIN.M with the given input arguments.%%      MAIN('Property','Value',...) creates a new MAIN or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before main_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to main_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 main% Last Modified by GUIDE v2.5 28-Jan-2009 23:39:02% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @main_OpeningFcn, ...                   'gui_OutputFcn',  @main_OutputFcn, ...                   'gui_LayoutFcn',  [] , ...                   'gui_Callback',   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});endif 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 main is made visible.function main_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 main (see VARARGIN)% Choose default command line output for mainhandles.output = hObject;%scrsz = get(0,'ScreenSize');%h = gcf;%set(h,'Position',[50 50 scrsz(3)/4 scrsz(4)/4]); % Update handles structureguidata(hObject, handles);global image; image=0;global image_edge; image_edge=0;global counter; counter=1;% UIWAIT makes main wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = main_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 structurevarargout{1} = handles.output;global image;image=0;% --------------------------------------------------------------------function file_1_Callback(hObject, eventdata, handles)% hObject    handle to file_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function image_1_Callback(hObject, eventdata, handles)% hObject    handle to edge_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function edge_1_Callback(hObject, eventdata, handles)% hObject    handle to edge_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global image_edge;global counter;if (image_edge==0)    msgboxText{1} =  'You have not opened an image!';     msgboxText{2} = 'Choose File->Open image...!';    msgbox(msgboxText,'Incorrect paramenter!', 'warn','modal');    return;else    if counter == 1    image_edge=rgb2gray(image_edge);    counter=counter+1;    end    endset(handles.edit_thr,'Enable','on');set(handles.pushbutton_edge,'Enable','on');set(handles.edit_av_rows,'Enable','off');set(handles.edit_av_col,'Enable','off');set(handles.edit_disk_radius,'Enable','off');set(handles.edit_g_rows,'Enable','off');set(handles.edit_g_col,'Enable','off');set(handles.edit_g_sigma,'Enable','off');set(handles.edit_l_alpha,'Enable','off');set(handles.edit_log_rows,'Enable','off');set(handles.edit_log_col,'Enable','off');set(handles.edit_log_sigma,'Enable','off');set(handles.edit_un_alpha,'Enable','off');set(handles.edit_m_len,'Enable','off');set(handles.edit_m_theta,'Enable','off');set(handles.pushbutton_filter,'Enable','off');% --------------------------------------------------------------------function openimage_1_Callback(hObject, eventdata, handles)% hObject    handle to openimage_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global image;global image_edge;global counter;counter=0;cla(handles.axes_edges);cla(handles.axes_original);[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'}, 'Pick an Image File');image = imread([pathname,filename]);axes(handles.axes_original);imshow(image);image_edge=image;%handles.image = image;%guidata(hObject, handles);%save color_image;  %save gray_image; % --------------------------------------------------------------------function save_1_Callback(hObject, eventdata, handles)% hObject    handle to save_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)savePlotWithinGUI(handles.axes_edges);% --------------------------------------------------------------------function sobel_1_Callback(hObject, eventdata, handles)% hObject    handle to sobel_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global edge_choice;edge_choice=1;% --------------------------------------------------------------------function help_1_Callback(hObject, eventdata, handles)% hObject    handle to help_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)    msgboxText{1} =  'This simple program is used to';    msgboxText{2} =  'Filter images and finds edges in them :)';     msgbox(msgboxText,'Filter&Edge', 'help','modal');% --------------------------------------------------------------------function prewitt_1_Callback(hObject, eventdata, handles)% hObject    handle to prewitt_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global edge_choice;edge_choice=2;% --------------------------------------------------------------------function roberts_1_Callback(hObject, eventdata, handles)% hObject    handle to roberts_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global edge_choice;edge_choice=3;% --------------------------------------------------------------------function log_1_Callback(hObject, eventdata, handles)% hObject    handle to log_edge (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=5;set(handles.edit_log_rows,'Enable','on');set(handles.edit_log_col,'Enable','on');set(handles.edit_log_sigma,'Enable','on');% --------------------------------------------------------------------function zerocross_1_Callback(hObject, eventdata, handles)% hObject    handle to zerocross_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global edge_choice;edge_choice=4;% --------------------------------------------------------------------function canny_1_Callback(hObject, eventdata, handles)% hObject    handle to canny_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global edge_choice;edge_choice=5;% --------------------------------------------------------------------function filter_1_Callback(hObject, eventdata, handles)% hObject    handle to filter_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global image;if (image==0)    msgboxText{1} =  'You have not opened an image!';     msgboxText{2} = 'Choose File->Open image...!';    msgbox(msgboxText,'Incorrect paramenter!', 'warn','modal');    return;endset(handles.edit_av_rows,'Enable','off');set(handles.edit_av_col,'Enable','off');set(handles.edit_disk_radius,'Enable','off');set(handles.edit_g_rows,'Enable','off');set(handles.edit_g_col,'Enable','off');set(handles.edit_g_sigma,'Enable','off');set(handles.edit_l_alpha,'Enable','off');set(handles.edit_log_rows,'Enable','off');set(handles.edit_log_col,'Enable','off');set(handles.edit_log_sigma,'Enable','off');set(handles.edit_un_alpha,'Enable','off');set(handles.edit_m_len,'Enable','off');set(handles.edit_m_theta,'Enable','off');set(handles.pushbutton_filter,'Enable','on');set(handles.edit_thr,'Enable','off');set(handles.pushbutton_edge,'Enable','off');% --- Executes during object creation, after setting all properties.function slider1_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor',[.9 .9 .9]);end% --------------------------------------------------------------------function average_1_Callback(hObject, eventdata, handles)% hObject    handle to average_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=1;set(handles.edit_av_rows,'Enable','on');set(handles.edit_av_col,'Enable','on');% --------------------------------------------------------------------function disk_1_Callback(hObject, eventdata, handles)% hObject    handle to disk_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=2;set(handles.edit_disk_radius,'Enable','on');% --------------------------------------------------------------------function gaussian_1_Callback(hObject, eventdata, handles)% hObject    handle to gaussian_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=3;set(handles.edit_g_rows,'Enable','on');set(handles.edit_g_col,'Enable','on');set(handles.edit_g_sigma,'Enable','on');% --------------------------------------------------------------------function laplacian_1_Callback(hObject, eventdata, handles)% hObject    handle to laplacian_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=4;set(handles.edit_l_alpha,'Enable','on');% --------------------------------------------------------------------function motion_1_Callback(hObject, eventdata, handles)% hObject    handle to motion_1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global choice;choice=6;set(handles.edit_m_len,'Enable','on');set(handles.edit_m_theta,'Enable','on');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -