function varargout = MATLAB(varargin)
% IMAGE MATLAB code for image.fig
% IMAGE, by itself, creates a new IMAGE or raises the existing
% singleton*.
%
% H = IMAGE returns the handle to a new IMAGE or the handle to
% the existing singleton*.
%
% IMAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE.M with the given input arguments.
%
% IMAGE('Property','Value',...) creates a new IMAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before image_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to image_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 image
% Last Modified by GUIDE v2.5 15-Oct-2017 20:42:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_OpeningFcn, ...
'gui_OutputFcn', @image_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 image is made visible.
function image_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 image (see VARARGIN)
% Choose default command line output for image
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = image_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 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)
[filename,pathname,filterindex]... %uigetfile用于打开一个检索文件的对话框,一般有三个参数,第一个参数为
=uigetfile({'*.*';'*.jpg';'*.tif';'*.png'},'选择图片',... %文件的格式(即后缀),第二个参数是该对话框的名称,
'C:\Users\Administrator\Desktop\My_Image'); %第三个参数的该对话框的默认打开路径,返回值为用户选择的文件路径和名称
if(filterindex==0)%filterindex为选择与否的结果,选择则为1,反之为0
return
else
str=[pathname filename]; %合成路径+文件名
im=imread(str); %读取图片
axes(handles.axes4); %使用axes4轴对象(创建一个轴图形对象)
imshow(im);
handles.img=im;%将原图像im当做handles句柄中的一个对象
guidata(hObject,handles);%保存当前窗口中的所有句柄
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
x=inputdlg({'请输入阈值x:'},'Enter Data',1,{'0.5'},'on');%创建输入对话框
y=cell2mat(x); %将cell包转换为char类型
z=str2double(y); %将char类型转换为数值型
% gray=graythresh(handles.img);%自动确定二值化阈值
I2 = im2bw(handles.img,z); %将原图按照输入阈值转换为二值图像
axes(handles.axes5);%划定axes5轴区域为图像显示窗口
imshow(I2);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=size(handles.img);%返回图片的宽和高以及维数
if numel(a)>2 %numel函数用于计算数组元素的个数
y=rgb2gray(handles.img);%将原图转换为灰度图
axes(handles.axes5);
imshow(y);
else
msgbox(' 已经是灰度图了!');%消息盒子
end
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName,filterindex] = uiputfile({'*.jpg','JPEG(*.jpg)';'*.bmp','Bitmap(*.bmp)';'*.gif','GIF(*.gif)';'*.*', 'All Files (*.*)'},'保存图片','C:\Users\Administrator\Desktop\image');
h=getframe(handles.axes5);%getframe用于捕获当前图形对象中的画面
imwrite(h.cdata,[PathName,FileName]);%cdata属性包含图像矩阵数据
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf); %关闭当前Figure窗口句柄
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% 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)
a=size(handles.img);
if(numel(a)>2)
gray=rgb2gray(handles.img);
else
gray=handles.img;
end
axes(handles.axes5);
imhist(gray);
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=size(handles.img);
if(numel(a)>2)
gray=rgb2gray(handles.img);
else
gray=handles.img;
end
I=histeq(gray);%histeq函数用于直方图均衡化
axes(handles.axes5);
imshow(I);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt={'输入阈值x:','输入阈值y'};%设置提示字符串
name='Enter Data';%设置标题
numlines=1;%指定输入数据的行数
defAns={'0','0'};%设定默认值
% Resize='on';%设定对话框尺寸可调节
answer=inputdlg(prompt,name,numlines,defAns,'on');%创建输入对话框
a=str2double(answer{1});
b=str2double(answer{2});
J=imadjust(handles.img,[a/255 b/255], [0 1]);
axes(handles.axes5);
imshow(J);
% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton6
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns
评论1