-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileLoad.m
68 lines (63 loc) · 2.44 KB
/
fileLoad.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function [h, errFlag] = fileLoad(hObject, eventdata, h)
errFlag = 0;
% uigetfile
if isfield(h, 'CurrentResultsFolder')
[FileName, PathName, ~] = ...
uigetfile('*.mat', 'Load Results File...', h.CurrentResultsFolder);
else
[FileName, PathName, ~] = ...
uigetfile('*.mat', 'Load Results File...', h.CurrentFolder);
end
if FileName ~= 0
load(fullfile(PathName, FileName));
else
warning('No file was selected');
errFlag = -1;
return;
end
if ~isfield(h, 'FileName')
% there is no video file open yet. let's open the one corresponding to
% the results file
h = openfile(hObject, eventdata, h, fullfile(state.CurrentFolder, state.FileName));
end
% check that it matches currently open video file
if isequal(state.FileName, h.FileName) && ...
length(state.analyzedFrames) == length(h.analyzedFrames)
% if matches load the results and state
h.results = results;
h.analyzedFrames = state.analyzedFrames;
h.roi = state.roi;
h.blinkRoi = state.blinkRoi;
h.blinkClassifier = state.blinkClassifier;
h.ThresholdSlider.Value = state.Threshold;
h.ThresholdText.String = sprintf('%3.1f', state.Threshold);
h.FilterSizeEdit.Value = state.FilterSize;
h.FilterSizeEdit.String = num2str(state.FilterSize);
h.CurrentResultsFileName = FileName;
h.CurrentResultsFolder = PathName;
len = sum(h.analyzedFrames);
h.ReplaySlider.Max = len;
h.ReplaySlider.Min = min(1, len);
[~, h.ReplaySlider.Value] = min(abs(find(h.analyzedFrames)-h.iFrame));
h.ReplaySlider.SliderStep = [min(1, 1/len), min(1, 10/len)];
else
% if doesn't match ask what to do
str = 'Results file does not match currently open video file. You can either "Load parameters only" (e.g. threshold value, ROIs, FilterSize), or "Cancel" and open the correct video file first.';
button = questdlg(str, ...
'File Mismatch', ...
'Load parameters only', 'Cancel', 'Cancel');
switch button
case 'Load parameters only'
h.roi = state.roi;
h.blinkRoi = state.blinkRoi;
h.blinkClassifier = state.blinkClassifier;
h.ThresholdSlider.Value = state.Threshold;
h.ThresholdText.String = sprintf('%3.1f', state.Threshold);
h.FilterSizeEdit.Value = state.FilterSize;
h.FilterSizeEdit.String = num2str(state.FilterSize);
case 'Cancel'
% do nothing
otherwise
% do nothing
end
end