function varargout = untitled(varargin)
% UNTITLED MATLAB code 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_OpeningFcn 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 27-May-2019 12:07:13
% 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 && 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 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;
set(handles.axes1,'visible','off');
set(handles.axes2,'visible','off');
set(handles.axes3,'visible','off');
% 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;
% --------------------------------------------------------------------
function Menu_1_Callback(hObject, eventdata, handles)
% hObject handle to Menu_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function openpic_Callback(hObject, eventdata, handles)
% hObject handle to openpic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像');
if isequal(filename,0)|isequal(pathname,0)
errordlg('没有选中文件','出错');
return;
else file=[pathname,filename];
%警告对话框提示输入合法图像文件
I=imread(file);
axes(handles.axes1);
imshow(I);title('原图像');
handles.I=I;
end
%Update handles structure
guidata(hObject,handles);
% --------------------------------------------------------------------
function savepic_Callback(hObject, eventdata, handles)
% hObject handle to savepic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[sfilename ,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像','untitled.jpg');
if ~isequal([sfilename,sfilepath],[0,0])
sfilefullname=[sfilepath ,sfilename];
h=getframe(handles.axes2);
imwrite(h.cdata,sfilefullname);
else
msgbox('你按了取消键 ','保存失败');
end
% --------------------------------------------------------------------
function Menu_2_Callback(hObject, eventdata, handles)
% hObject handle to Menu_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Menu_2_1_Callback(hObject, eventdata, handles)
% hObject handle to Menu_2_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.I;
axes(handles.axes2);
J=rgb2gray(I);
imshow(J);title('真彩图像转灰度图像');
% --------------------------------------------------------------------
function Menu_2_2_Callback(hObject, eventdata, handles)
% hObject handle to Menu_2_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.I;
axes(handles.axes2);
[X,map]=rgb2ind(I,12);
imshow(X,map);
title('真彩图像转索引图像');
% --------------------------------------------------------------------
function Menu_2_3_Callback(hObject, eventdata, handles)
% hObject handle to Menu_2_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.I;
axes(handles.axes2);
J=im2bw(I,0.4);
imshow(J);title('真彩图像转二值图像');
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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)
%清除视图图片
cla(handles.axes2,'reset'); %handles.axes2为显示图片窗口,reset即清除
cla(handles.axes3,'reset');
set(handles.axes2,'visible','off');
set(handles.axes3,'visible','off');
% 重置清空动态txt的文字
set(handles.edit1,'string',''); %handles.edit1为要清除文字的文本框
% --------------------------------------------------------------------
function Menu_3_Callback(hObject, eventdata, handles)
% hObject handle to Menu_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Menu_3_1_Callback(hObject, eventdata, handles)
% hObject handle to Menu_3_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.I;
axes(handles.axes2);
image_size=size(I);
dimension=numel(image_size);
if dimension==3
B=rgb2gray(I);
C=fftshift(fft2(B)); %计算傅里叶变换并移位
imshow(log(abs(C)),[]); %显示傅里叶变换谱
else
S=fftshift(fft2(I)); %计算傅里叶变换并移位
imshow(log(abs(S)),[]); %显示傅里叶变换谱
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
%获取text文本框的数字,竖直平移X的数值
global x;%定义一个x的全局变量
x=str2num(get(hObject,'String'));
% --- Executes during object creation, after setting