function varargout = shuyeshibie(varargin)
% SHUYESHIBIE MATLAB code for shuyeshibie.fig
% SHUYESHIBIE, by itself, creates a new SHUYESHIBIE or raises the existing
% singleton*.
%
% H = SHUYESHIBIE returns the handle to a new SHUYESHIBIE or the handle to
% the existing singleton*.
%
% SHUYESHIBIE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SHUYESHIBIE.M with the given input arguments.
%
% SHUYESHIBIE('Property','Value',...) creates a new SHUYESHIBIE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before shuyeshibie_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to shuyeshibie_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 shuyeshibie
% Last Modified by GUIDE v2.5 15-Feb-2019 11:13:36
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @shuyeshibie_OpeningFcn, ...
'gui_OutputFcn', @shuyeshibie_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 shuyeshibie is made visible.
function shuyeshibie_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 shuyeshibie (see VARARGIN)
% Choose default command line output for shuyeshibie
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes shuyeshibie wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = shuyeshibie_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)
clc;
ax1=(handles.axes1);cla(ax1,'reset')
ax2=(handles.axes2);cla(ax2,'reset')
ax3=(handles.axes3);cla(ax3,'reset')
ax4=(handles.axes4);cla(ax4,'reset')
ax5=(handles.axes5);cla(ax5,'reset')
ax6=(handles.edit1);cla(ax6,'reset')
[name,path]=uigetfile({'*.png';'*.bmp';'tif'},'载入图像');
x=imread([path,name]); %获取位置
axes(handles.axes1);%axes表示获取位置,这里选取的位置为axes1;
imshow(x); %显示图像
title('测试原图')
f=x;
save('f'); %保存变量
guidata(hObject,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)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
load('f')
%f=imread('3.png');%读入测试图
%f=rgb2gray(f);
A=double(f);%把灰度值转化为双精度
g=mat2gray(A);%灰度值归一化0到1之间
k=im2bw(g,0.4);%二值化,阈值0.4
axes(handles.axes2)
imshow(k)
title('二值化图')
k=1-k;%反转
se=strel('disk',6);
fc=imclose(k,se);%闭运算
fc=imfill(fc,'hole');%填洞
axes(handles.axes3),imshow(fc);
title('填洞')
se=strel('disk',8);
fco=imopen(fc,se);%开运算
axes(handles.axes4),imshow(fco);
title('开运算');
BW=fco;
trainset=train(); %%%%请联系QQ609553134
msgbox('待完善,Q609553134')
trainset2=train2();%训练样本
axes(handles.axes5)
imshow(f,[]);
title('结果图')
[L,num] = bwlabel(BW); %标记
for t=1:num
[r c]=find(L==t);
r1=min(r);
c1=min(c);
r2=max(r);
c2=max(c);
IM{t}=BW(r1:r2,c1:c2);
% figure;imshow(BW(r1:r2,c1:c2))
phi=invmoments(IM{t}); %提取不变矩特征
Pset{t}=phi;
d(t)=norm(abs(log(Pset{t}(1:7)))-abs(log(trainset(1:7)))); %与训练样本进行匹配
d2(t)=norm(abs(log(Pset{t}(1:7)))-abs(log(trainset2(1:7))));
% [M N]=min(d);
% result{t}=b(N); %保存结果
if d(t)<10
text((c2+c1)/2,(r2+r1)/2,'枫叶','BackgroundColor','red'); %显示结果
set(handles.edit1,'string','枫叶');
msgbox(strcat('检测结果为:','枫叶!'), '对话框标题');
[s,fs]=wavread('fengye.wav')
wavplay(s,8000)
end
if d2(t)<10
text((c2+c1)/2,(r2+r1)/2,'灵叶','BackgroundColor','green'); %显示结果
set(handles.edit1,'string','灵叶');
msgbox(strcat('检测结果为:','灵叶!'), '对话框标题');
[s,fs]=wavread('lingye.wav')
wavplay(s,8000)
end
if Pset{t}(3:7)<0.00001
text((c2+c1)/2,(r2+r1)/2,'百合叶','BackgroundColor','yellow'); %显示结果
set(handles.edit1,'string','百合叶');
msgbox(strcat('检测结果为:','百合叶!'), '对话框标题');
[s,fs]=wavread('baiheye.wav')
wavplay(s,8000)
end
end
% 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)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
msgbox(strcat('本设计为基于几何不变矩的树叶识别系统'), '说明');
% 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)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
clc;
close all;
% 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)
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
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end