function varargout = untitlegui(varargin)
% UNTITLEGUI MATLAB code for untitlegui.fig
% UNTITLEGUI, by itself, creates a new UNTITLEGUI or raises the existing
% singleton*.
%
% H = UNTITLEGUI returns the handle to a new UNTITLEGUI or the handle to
% the existing singleton*.
%
% UNTITLEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLEGUI.M with the given input arguments.
%
% UNTITLEGUI('Property','Value',...) creates a new UNTITLEGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitlegui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitlegui_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 untitlegui
% Last Modified by GUIDE v2.5 06-May-2018 13:54:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitlegui_OpeningFcn, ...
'gui_OutputFcn', @untitlegui_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 untitlegui is made visible.
function untitlegui_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 untitlegui (see VARARGIN)
% Choose default command line output for untitlegui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitlegui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitlegui_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 pushbutton1.
function uipushtool4_ClickedCallback(hObject, eventdata, handles)
global im
[filename,pathname] = uigetfile('*.jpg','选择图像文件');
im = imread(fullfile(pathname,filename));
axes(handles.axes1);
imshow(im);
% hObject handle to uipushtool4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
% --- Executes on button press in pushbutton4.
function pushbutton1_Callback(hObject, eventdata, handles)
global im
rgb = im;
if ndims(rgb) == 3
I = rgb2gray(rgb);
else
I = rgb;
end
axes(handles.axes1);
imshow(I); title('灰度图');
imwrite(I,'灰度图.jpg')%保存图像为文件
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
clc,clear,close all
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function pushbutton4_Callback(hObject, eventdata, handles)
I = imread('灰度图.jpg')
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
axes(handles.axes1);
imshow(gradmag,[]), title('梯度幅值图像')
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
set(hObject,'xTick',[]);
set(hObject,'ytick',[]);
set(hObject,'box','on');
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
评论0