function varargout = guijiemian(varargin)
% GUIJIEMIAN MATLAB code for guijiemian.fig
% GUIJIEMIAN, by itself, creates a new GUIJIEMIAN or raises the existing
% singleton*.
%
% H = GUIJIEMIAN returns the handle to a new GUIJIEMIAN or the handle to
% the existing singleton*.
%
% GUIJIEMIAN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIJIEMIAN.M with the given input arguments.
%
% GUIJIEMIAN('Property','Value',...) creates a new GUIJIEMIAN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before guijiemian_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to guijiemian_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 guijiemian
% Last Modified by GUIDE v2.5 18-Jun-2014 13:56:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @guijiemian_OpeningFcn, ...
'gui_OutputFcn', @guijiemian_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 guijiemian is made visible.
function guijiemian_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 guijiemian (see VARARGIN)
% Choose default command line output for guijiemian
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guijiemian wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = guijiemian_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 dakaituxiang.
function dakaituxiang_Callback(hObject, eventdata, handles)
% hObject handle to dakaituxiang (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im %定义全局变量,以便其它回调函数使用
[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'选择图像');
if isequal(filename,0)||isequal(pathname,0)
errordlg('您还没有选取图片!!','温馨提示'); %如果没有输入,则创建错误对话框
return;
else
image=[pathname,filename]; %合成路径+文件名
im=imread(image); %读取图像
set(handles.axes1,'HandleVisibility','ON'); %打开坐标,方便操作
axes(handles.axes1); %使用图像,操作在坐标轴1
imshow(im); %在坐标axes1显示原图像
end
% --- Executes on button press in zhifangtu.
function zhifangtu_Callback(hObject, eventdata, handles)
% hObject handle to zhifangtu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
set(handles.axes2,'HandleVisibility','ON'); %打开坐标,方便操作
axes(handles.axes2);
imhist(im);
% --- Executes on button press in yuzhifenge.
function yuzhifenge_Callback(hObject, eventdata, handles)
% hObject handle to yuzhifenge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
im1=im;
im1=double(im1);
T=(min(im1(:))+max(im1(:)))/2;
done=false;
i=0;
while ~done
r1=find(im1<=T);
r2=find(im1>T);
Tnew=(mean(im1(r1))+mean(im1(r2)))/2;
done=abs(Tnew-T)<1;
T=Tnew;
i=i+1;
end
im1(r1)=0;
im1(r2)=1;
set(handles.axes3,'HandleVisibility','ON'); %打开坐标,方便操作
axes(handles.axes3);
imshow(im1);
% --- Executes on button press in quyushengzhang.
function quyushengzhang_Callback(hObject, eventdata, handles)
% hObject handle to quyushengzhang (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
if ndims(im)==3
I=rgb2gray(im);
else
I=im;
end
I=double(I);
[M,N]=size(I);
seedx=30;
seedy=50;
hold on
seed=I(seedx,seedy);
Y=zeros(M,N);
Y(seedx,seedy)=1;
count=1;
threshold=50;
while count>0
count=0;
for i=1:M
for j=1:N
if Y(i,j)==1
if(i-1)>0 &&(i+1)<(M+1) &&(j-1)>0 &&(j+1)<(N+1)
for u=-1:1
for v=-1:1
if Y(i+u,j+v)==0 && abs(I(i+u,j+v)-seed)<=threshold
Y(i+u,j+v)=1;
count=count+1;
% s=s+I(i+u,j+v);
end
end
end
end
end
end
end
end
axes(handles.axes4);
imshow(Y);title('区域生长结果');
% --- Executes on button press in fenliehebing.
function fenliehebing_Callback(hObject, eventdata, handles)
% hObject handle to fenliehebing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
im3=im;
im3=splitmerge(im3,2,@predicate);%调用splitmerge函数对图像进行分裂合并
% set(handles.axes5,'HandleVisibility','ON'); %打开坐标,方便操作
axes(handles.axes5);
imshow(im3);
% --- Executes on button press in baocuntuxiang.
function baocuntuxiang_Callback(hObject, eventdata, handles)
% hObject handle to baocuntuxiang (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uiputfile({'*.jpg';...
'*.bmp';... %pathname获取保存数据路径,filename获取保存 数据名称
'*.gif';... %'*.jpg' '*.bmp' '*.gif为保存格式
}, '保存图像');
if FileName==0 %判断是否输入保存图像文件名,否则等待输入文件名再进入下一步操作
return;
else
h=getframe(handles.axes1); %获取axes2坐标轴中的结构体(struct),赋值给变量h
imwrite(h.cdata,[PathName,FileName]);%用imwrite函数保存图像,默认保存格式为jpg(h.data为结构体中的图像数据)
end
% --- Executes on button press in tuichu.
function tuichu_Callback(hObject, eventdata, handles)
% hObject handle to tuichu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
评论0