function varargout = ChooseData(varargin)
% CHOOSEDATA MATLAB code for ChooseData.fig
% CHOOSEDATA, by itself, creates a new CHOOSEDATA or raises the existing
% singleton*.
%
% H = CHOOSEDATA returns the handle to a new CHOOSEDATA or the handle to
% the existing singleton*.
%
% CHOOSEDATA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CHOOSEDATA.M with the given input arguments.
%
% CHOOSEDATA('Property','Value',...) creates a new CHOOSEDATA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ChooseData_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ChooseData_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 ChooseData
% Last Modified by GUIDE v2.5 23-Mar-2019 12:19:26
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ChooseData_OpeningFcn, ...
'gui_OutputFcn', @ChooseData_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 ChooseData is made visible.
function ChooseData_OpeningFcn(hObject, ~, 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 ChooseData (see VARARGIN)
% Choose default command line output for ChooseData
set(hObject, 'toolbar', 'figure');
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ChooseData wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ChooseData_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
global data imageflag dataflag X Y AREA
data = 0;
imageflag = 0;
dataflag = 0;
X = 0;
Y = 0;
AREA = 0;
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)
global imageflag height width
[filename, pathname] = uigetfile('*.bmp', '请选择图片');
IMG = imread([pathname filename]);
[height, width] = size(IMG);
axes(handles.axes1);
image(IMG);
imageflag = 1;
% --- 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)
global imageflag height width data dataflag
if(imageflag ~= 1)
errordlg('请先选择图片!');
return;
end
[filename, pathname] = uigetfile('*.txt', '请选择数据文件');
data = load([pathname filename]);
datalength = length(data);
if(datalength ~= height * width)
errordlg('数据与图像大小不匹配!');
return;
end
data = reshape(data, [width height])';
dataflag = 1;
% --- 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)
global X Y AREA
h = datacursormode;
s = getCursorInfo(h);
if(length(s) < 3)
errordlg('格点数目不足');
return;
end
X = zeros(length(s), 1);
Y = zeros(length(s), 1);
for i = 1 : length(s)
X(i) = s(i).Position(1);
Y(i) = s(i).Position(2);
end
[~, AREA] = convhull(X, Y);
% --- 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)
global X Y AREA data dataflag
if(dataflag ~= 1)
errordlg('未选择数据文件!');
return;
end
array = zeros( ( max(X) - min(X) + 1 )*( max(Y) - min(Y) + 1 ), 1);
num = 0;
for i = min(X) : max(X)
for j = min(Y) : max(Y)
x = [X; i];
y = [Y; j];
[~, area] = convhull(x, y);
if(area < AREA * 1.0001)
num = num + 1;
array(num) = data(i, j);
end
end
end
array = array(1 : num);
xlswrite('part.xlsx', array);