matlab-GUI—菜单栏应用
- 新建空白GUIDE,打开菜单编辑器,添加修改菜单栏名字
-
打开编辑器,编写菜单栏下各标记函数,编辑器完成后,就可生成效果图了
- 填充程序如下,其中test.jpg需要全部修改为需要处理的图,并将m文件、fig文件和图片放置当前路径,即可运行图片处理程序了
function varargout = Digital_figure_prosses(varargin) % DIGITAL_FIGURE_PROSSES MATLAB code for Digital_figure_prosses.fig % DIGITAL_FIGURE_PROSSES, by itself, creates a new DIGITAL_FIGURE_PROSSES or raises the existing % singleton*. % % H = DIGITAL_FIGURE_PROSSES returns the handle to a new DIGITAL_FIGURE_PROSSES or the handle to % the existing singleton*. % % DIGITAL_FIGURE_PROSSES(\'CALLBACK\',hObject,eventData,handles,...) calls the local % function named CALLBACK in DIGITAL_FIGURE_PROSSES.M with the given input arguments. % % DIGITAL_FIGURE_PROSSES(\'Property\',\'Value\',...) creates a new DIGITAL_FIGURE_PROSSES or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Digital_figure_prosses_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Digital_figure_prosses_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 Digital_figure_prosses % Last Modified by GUIDE v2.5 21-Aug-2018 19:29:28 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct(\'gui_Name\', mfilename, ... \'gui_Singleton\', gui_Singleton, ... \'gui_OpeningFcn\', @Digital_figure_prosses_OpeningFcn, ... \'gui_OutputFcn\', @Digital_figure_prosses_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 Digital_figure_prosses is made visible. function Digital_figure_prosses_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 Digital_figure_prosses (see VARARGIN) % Choose default command line output for Digital_figure_prosses handles.output = hObject; % Update handles structure guidata(hObject, handles); imshow(\'test.jpg\') % UIWAIT makes Digital_figure_prosses wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Digital_figure_prosses_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; % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_3_Callback(hObject, eventdata, handles) % hObject handle to Untitled_3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_4_Callback(hObject, eventdata, handles) % hObject handle to Untitled_4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear; I=imread(\'test.jpg\'); gray=rgb2gray(I); J=histeq(gray,32); [ counts,x]=imhist(J); I=imread(\'test.jpg\'); Q=rgb2gray(I); [counts,x]=imhist(J);I=imread(\'test.jpg\');Q=rgb2gray(I); subplot(2,2,1),imshow(Q);title(\'原始heart灰度图像\'); subplot(2,2,3),imhist(Q);title(\'原始heart灰度图像的直方图\'); M=histeq(Q,counts); subplot(2,2,2),imshow(M);title(\'直方图规定化后的heart灰度图像\'); subplot(2,2,4),imhist(M);title(\'直方图均衡化成32个灰度级后的heart灰度图像直方图\'); axis square; % -------------------------------------------------------------------- function Untitled_5_Callback(hObject, eventdata, handles) % hObject handle to Untitled_5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) I=imread(\'test.jpg\');V=0.02;noisel=imnoise(I,\'gaussian\',0,V);%加高斯噪声 subplot(2,2,1),imshow(noisel);title(\'加高斯噪声\'); noise=0.1*randn(size(I));%加随机噪声 noise2=imadd(I,im2uint8(noise)); subplot(2,2,2),imshow(noise2);title(\'加随机噪声\') noise3=imnoise(I,\'salt & pepper\',0.02); subplot(2,2,3),imshow(noise3);title(\'加椒盐噪声\') noise4=imnoise(I,\'speckle\',0.06); subplot(2,2,4),imshow(noise4);title(\'加乘性噪声\') % -------------------------------------------------------------------- function Untitled_6_Callback(hObject, eventdata, handles) % hObject handle to Untitled_6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear; I=imread(\'test.jpg\');H=fspecial(\'sobel\'); subplot(1,2,1),imshow(I);title(\'原始heart灰度图像\'); J=imfilter(I,H); subplot(1,2,2),imshow(J);title(\'Sobel算子对图像锐化结果\'); % -------------------------------------------------------------------- function Untitled_7_Callback(hObject, eventdata, handles) % hObject handle to Untitled_7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear; I1=imread(\'test.jpg\'); I=rgb2gray(I1); BW1=edge(I,\'sobel\'); BW2=edge(I,\'Canny\'); BW3=edge(I,\'Prewitt\'); BW4=edge(I,\'log\');subplot(3,2,1),imshow(I); title(\'原始heart灰度图像\');subplot(3,2,3),imshow(BW1); title(\'Sobel边缘检测\');subplot(3,2,4),imshow(BW2); title(\'Canny边缘检测\');subplot(3,2,5),imshow(BW3); title(\'prewitt 边缘检测\'); subplot(3,2,6),imshow(BW4);title(\'log边缘检测\'); % -------------------------------------------------------------------- function Untitled_8_Callback(hObject, eventdata, handles) % hObject handle to Untitled_8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------图像缩放------------------------------------------------------- function Untitled_9_Callback(hObject, eventdata, handles) % hObject handle to Untitled_9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear; I=imread(\'test.jpg\'); subplot(2,2,1),imshow(I);title(\'原始图像\'); X1=imresize(I,0.1,\'nearest\'); subplot(2,2,2),imshow(X1,[]);title(\'最近邻插值法实现图像缩放\'); X2=imresize(I,0.1,\'bilinear\'); subplot(2,2,3),imshow(X2,[]);title(\'双线性插值法实现图像缩放\'); X2=imresize(I,0.1,\'bilinear\'); subplot(2,2,3),imshow(X2,[]);title(\'双线性插值法实现图像缩放\'); X3=imresize(I,0.1,\'bicubic\'); subplot(2,2,4),imshow(X3,[]);title(\'双立方插值法实现图像缩放\'); % -------------------------------------------------------------------- function Untitled_10_Callback(hObject, eventdata, handles) % hObject handle to Untitled_10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------图像裁剪------------------------------------------------------- function Untitled_11_Callback(hObject, eventdata, handles) % hObject handle to Untitled_11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear; I=imread(\'test.jpg\'); %subplot(1,1,1),imshow(I);title(\'请选择要裁剪的区域,并双击选定区域以显示\'); msgbox(\'请选择要裁剪的区域,并双击选定区域以显示\',\'提示信息\'); waitforbuttonpress; clf; I2=imcrop(I); close;%右键点击“crop image” subplot(1,2,1),imshow(I);title(\'原始heart——RGB图像\'); subplot(1,2,2),imshow(I2);title(\'裁剪后的heart——RGB图像\'); % -------------------------------------------------------------------- function Untitled_12_Callback(hObject, eventdata, handles) % hObject handle to Untitled_12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_13_Callback(hObject, eventdata, handles) % hObject handle to Untitled_13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)