function varargout = PatternRecognition(varargin)
% PATTERNRECOGNITION MATLAB code for PatternRecognition.fig
% PATTERNRECOGNITION, by itself, creates a new PATTERNRECOGNITION or raises the existing
% singleton*.
%
% H = PATTERNRECOGNITION returns the handle to a new PATTERNRECOGNITION or the handle to
% the existing singleton*.
%
% PATTERNRECOGNITION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PATTERNRECOGNITION.M with the given input arguments.
%
% PATTERNRECOGNITION('Property','Value',...) creates a new PATTERNRECOGNITION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before PatternRecognition_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to PatternRecognition_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 PatternRecognition
% Last Modified by GUIDE v2.5 11-Apr-2018 21:12:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @PatternRecognition_OpeningFcn, ...
'gui_OutputFcn', @PatternRecognition_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 PatternRecognition is made visible.
function PatternRecognition_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 PatternRecognition (see VARARGIN)
% Choose default command line output for PatternRecognition
handles.output = hObject;
global i;
global j;
global k;
i = 0;
j = 0;
k = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes PatternRecognition wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = PatternRecognition_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 selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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
% --- 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)
clear global;
global data;
axes(handles.axes3);
[filename, pathname] = uigetfile({'*.bmp;*.jpg;*.png;*.jpeg', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg)'; '*.*', 'All Files (*.*)'},'选择图像');
if isequal(filename,0) || isequal(pathname,0)
errordlg('您没选取图片','温馨提示');%没输入则创建错误框
return;
end
fpath = [pathname,filename];
data = imread(fpath); %读取图像
hImage = image(data); %显示图像,同时获得图像的句柄
set(hImage,'ButtonDownFcn',{@myCallback,handles});%设置图像对象的Button。。回调函数为自己定义的MyCallback
handles.hImage = hImage;%保存图像的句柄handles结构
guidata(hObject, handles);
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%鼠标点击读取RGB信息
function myCallback(hObject, eventdata, handles)
global liststr1;
global liststr2;
global liststr3;
global Landsampledata;
global Skysampledata;
global Wavesampledata;
global i;
global j;
global k;
global data;
% global choose;
global flag;
switch flag
case 1%天空样本点
pot = get(gca,'currentpoint');
potx = round(pot(1,1));
poty = round(pot(1,2));
R = num2str(data(poty,potx,1));
G = num2str(data(poty,potx,2));
B = num2str(data(poty,potx,3));
%存储样本点
i = length(liststr1)+1;
Skysampledata(i,1) = data(poty,potx,1);
Skysampledata(i,2) = data(poty,potx,2);
Skysampledata(i,3) = data(poty,potx,3);
%显示样本点
str = [R,' ',G,' ',B];
liststr1{length(liststr1)+1} = str;
text(potx,poty,'x','Color','green','FontSize',10);
set(handles.listbox1,'string',liststr1);
case 2%陆地样本点
pot = get(gca,'currentpoint');
potx = round(pot(1,1));
poty = round(pot(1,2));
R = num2str(data(poty,potx,1));
G = num2str(data(poty,potx,2));
B = num2str(data(poty,potx,3));
%存储样本点
j = length(liststr2)+1;
Landsampledata(j,1) = data(poty,potx,1);
Landsampledata(j,2) = data(poty,potx,2);
Landsampledata(j,3) = data(poty,potx,3);
%显示样本点
str = [R,' ',G,' ',B];
liststr2{length(liststr2)+1} = str;
text(potx,poty,'o','Color','red','FontSize',8);
set(handles.listbox2,'string',liststr2);
case 3%波浪样本点
pot = get(gca,'currentpoint');
potx = round(pot(1,1));
poty = round(pot(1,2));
R = num2str(data(poty,potx,1));
G = num2str(data(poty,potx,2));
B = num2str(data(poty,potx,3));
%存储样本点
k = length(liststr3)+1;
Wavesampledata(k,1) = data(poty,potx,1);
Wavesampledata(k,2) = data(poty,potx,2);
Wavesampledata(k,3) = data(poty,potx,3);
%显示样本点
str = [R,' ',G,' ',B];
liststr3{length(liststr3)+1} = str;
text(potx,poty,'+','Color','red','FontSize',10);
set(handles.listbox3,'string',liststr3);
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)
close(findobj('Tag','figure1'));%关闭主窗口
% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to b