Skip to content

Commit 0f3d3d1

Browse files
committed
v0.1.7
[v0.1.7, 7/23/2018] Added "Summary" button in GUI Added "Export" button in GUI Robust video loading, number of frames calculated 3 times and max is taken. Updated "List Files" button for Trialset Added "Learning Curve" button for Trialset Settings box now displays new lines Faster video loading (~2x, requires a "Distrib_Computing_Toolbox")
1 parent ce62e4a commit 0f3d3d1

File tree

12 files changed

+698
-121
lines changed

12 files changed

+698
-121
lines changed

GUI.fig

2.48 KB
Binary file not shown.

GUI.m

Lines changed: 128 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
% Edit the above text to modify the response to help GUI
2424

25-
% Last Modified by GUIDE v2.5 12-Jul-2018 17:40:09
25+
% Last Modified by GUIDE v2.5 23-Jul-2018 16:44:51
2626

2727
% Begin initialization code - DO NOT EDIT
2828
gui_Singleton = 1;
@@ -56,7 +56,8 @@ function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
5656
handles.output = hObject;
5757

5858
% Update settings window
59-
csSettings = importdata('settings_vistrack.m', '\n');
59+
% csSettings = importdata('settings_vistrack.m', '\n');
60+
csSettings = file2cellstr_('settings_vistrack.m');
6061
set(handles.editSettings, 'String', csSettings);
6162

6263
[vcVer, vcVer_date] = version_();
@@ -73,6 +74,15 @@ function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
7374
% uiwait(handles.figure1);
7475

7576

77+
function csLines = file2cellstr_(vcFile)
78+
% read text file to a cell string
79+
fid = fopen(vcFile, 'r');
80+
csLines = {};
81+
while ~feof(fid), csLines{end+1} = fgetl(fid); end
82+
fclose(fid);
83+
csLines = csLines';
84+
85+
7686
% --- Outputs from this function are returned to the command line.
7787
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
7888
% varargout cell array for returning output args (see VARARGOUT);
@@ -122,6 +132,7 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
122132
vidFname = fullfile(PathName, FileName);
123133
end
124134
handles.vidFname = vidFname;
135+
buttons_off_(handles);
125136

126137
% Set result field
127138
vcFile_out = subsFileExt_(vidFname, '_Track.mat');
@@ -133,7 +144,7 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
133144
set(handles.btnSync, 'Enable', 'off');
134145
set(handles.btnBackground, 'Enable', 'off');
135146
set(handles.btnTrack, 'Enable', 'off');
136-
set(handles.btnPreview, 'Enable', 'off');
147+
set(handles.btnPreview, 'Enable', 'off');
137148
set(handles.btnSave, 'Enable', 'on');
138149
set(handles.panelPlot, 'Visible', 'on');
139150
return;
@@ -145,12 +156,17 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
145156
set(handles.editResultFile, 'String', '');
146157
end
147158

148-
try
159+
try
149160
set(handles.edit1, 'String', handles.vidFname);
150161
h = msgbox('Loading... (this will close automatically)');
151-
handles.vidobj = VideoReader(handles.vidFname);
152-
handles.vidobj
153-
try close(h); catch, end;
162+
% handles.vidobj = VideoReader(handles.vidFname);
163+
handles.vidobj = vistrack('VideoReader', vidFname);
164+
fprintf('Video file info: %s\n', handles.vidFname);
165+
disp(handles.vidobj);
166+
% fprintf('Calculating number of frames...\n');
167+
fprintf('\t# video frames: %d\n', handles.vidobj.NumberOfFrames);
168+
close_(h);
169+
154170
set(handles.btnSync, 'Enable', 'on');
155171
set(handles.btnBackground, 'Enable', 'off');
156172
set(handles.btnTrack, 'Enable', 'off');
@@ -186,6 +202,14 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
186202
end
187203

188204

205+
function buttons_off_(handles)
206+
set(handles.btnSync, 'Enable', 'off');
207+
set(handles.btnBackground, 'Enable', 'off');
208+
set(handles.btnTrack, 'Enable', 'off');
209+
set(handles.btnPreview, 'Enable', 'off');
210+
set(handles.btnSave, 'Enable', 'off');
211+
set(handles.panelPlot, 'Visible', 'off');
212+
189213

190214
function editSettings_Callback(hObject, eventdata, handles)
191215
% hObject handle to editSettings (see GCBO)
@@ -1052,14 +1076,8 @@ function btnLoadPrev_Callback(hObject, eventdata, handles)
10521076
'SE' ,'thresh' ,'AreaTarget' ,'WINPOS' ,'img0', ...
10531077
'XC' ,'YC' ,'AC' ,'xy_names' ,'ang_names' ,'csSettings', ...
10541078
'ADC', 'ADCTS', ...
1055-
'MOV', 'XC_off', 'YC_off', 'vidFname', 'ESAC'};
1056-
for i=1:numel(csFields)
1057-
try
1058-
eval(sprintf('handles.%s = S.%s;', csFields{i}, csFields{i}));
1059-
catch
1060-
;
1061-
end
1062-
end
1079+
'MOV', 'XC_off', 'YC_off', 'vidFname', 'ESAC', 'vcVer', 'vcVer_date'};
1080+
handles = struct_merge_(handles, S, csFields);
10631081

10641082
set(handles.edit1, 'String', handles.vidFname);
10651083
set(handles.editADCfile, 'String', [handles.vidFname(1:end-4), '_Rs.mat']);
@@ -1091,23 +1109,27 @@ function btnSave_Callback(hObject, eventdata, handles)
10911109

10921110
%save file
10931111
h = msgbox('Saving... (this will close automatically)');
1094-
S_save = copyStruct_(handles, {'TLIM0', 'FLIM0', 'FPS', ...
1112+
S_save = struct_copy_(handles, {'TLIM0', 'FLIM0', 'FPS', ...
10951113
'MASK' ,'xy_init' ,'vec0' ,'xy0' ,'TC' ,'TLIM' ,'FLIM' ,'img1' ,'img00', ...
10961114
'SE' ,'thresh' ,'AreaTarget' ,'WINPOS' ,'img0', ...
10971115
'XC' ,'YC' ,'AC' ,'xy_names' ,'ang_names' ,'csSettings', ...
10981116
'ADC', 'ADCTS', ...
10991117
'MOV', 'XC_off', 'YC_off', 'vidFname', 'ESAC'});
1118+
[S_save.vcVer, S_save.vcVer_date] = vistrack('version');
1119+
1120+
if exist_file_(handles.vidFname)
1121+
vcFile_mat = subsFileExt_(handles.vidFname, '_Track.mat');
1122+
else
1123+
vcFile_mat = get(handles.editResultFile, 'String');
1124+
end
11001125
try
1101-
[pathstr, name, ext] = fileparts(handles.vidFname);
1102-
outfname = fullfile(pathstr, [name, '_Track.mat']);
1103-
eval(sprintf('save(''%s'', ''-struct'', ''S_save'');', outfname));
1126+
eval(sprintf('save(''%s'', ''-struct'', ''S_save'');', vcFile_mat));
11041127
catch
1105-
outfname = get(handles.editResultFile, 'String');
1106-
eval(sprintf('save(''%s'', ''-struct'', ''S_save'');', outfname));
1128+
fprintf(2, 'Save file failed: %s\n', vcFile_mat);
11071129
end
11081130
close_(h);
1109-
set(handles.editResultFile, 'String', outfname);
1110-
msgbox_(sprintf('Output saved to %s', outfname));
1131+
set(handles.editResultFile, 'String', vcFile_mat);
1132+
msgbox_(sprintf('Output saved to %s', fullpath_(vcFile_mat)));
11111133

11121134

11131135
% --- Executes during object creation, after setting all properties.
@@ -1214,7 +1236,12 @@ function disp_adc_title_(ADCTC)
12141236
if isempty(vcFile)
12151237
flag = 0;
12161238
else
1217-
flag = ~isempty(dir(vcFile));
1239+
S_dir = dir(vcFile);
1240+
if numel(S_dir) == 1
1241+
flag = ~S_dir.isdir;
1242+
else
1243+
flag = 0;
1244+
end
12181245
end
12191246
if fVerbose && ~flag
12201247
fprintf(2, 'File does not exist: %s\n', vcFile);
@@ -1287,13 +1314,18 @@ function btnLoadTrialSet_Callback(hObject, eventdata, handles)
12871314
% handles structure with handles and user data (see GUIDATA)
12881315

12891316
vcFile_trialset = get(handles.editTrialSet, 'String');
1290-
[FileName,PathName,FilterIndex] = uigetfile('*.trialset', ...
1291-
'Select trialset', vcFile_trialset);
1292-
if ~FilterIndex, return; end
1293-
vcFile_trialset = fullfile(PathName, FileName);
1317+
if ~exist_file_(vcFile_trialset)
1318+
[FileName,PathName,FilterIndex] = uigetfile('*.trialset', ...
1319+
'Select trialset', vcFile_trialset);
1320+
if ~FilterIndex, return; end
1321+
vcFile_trialset = fullfile(PathName, FileName);
1322+
else
1323+
vcFile_trialset = fullpath_(vcFile_trialset);
1324+
end
12941325
set(handles.editTrialSet, 'String', vcFile_trialset);
12951326
set(handles.panelTrialSet, 'Visible', 'on');
12961327
edit(vcFile_trialset);
1328+
msgbox(sprintf('Loaded %s', vcFile_trialset), 'Loading Trialset');
12971329

12981330

12991331
% --- Executes on button press in btnEditTrialset.
@@ -1309,9 +1341,8 @@ function btnLearningCurve_Callback(hObject, eventdata, handles)
13091341
% hObject handle to btnLearningCurve (see GCBO)
13101342
% eventdata reserved - to be defined in a future version of MATLAB
13111343
% handles structure with handles and user data (see GUIDATA)
1312-
S_trialset = file2struct(get_str_(handles.editTrialSet));
1313-
[csFiles_Track, csDir_trial] = find_files_(S_trialset.vcDir, '*_Track.mat');
1314-
[cvrPathLen, cvrDuration] = vistrack('measure_trials', csFiles_Track, S_trialset.csAnimals);
1344+
vistrack('trialset-learningcurve', get_str_(handles.editTrialSet));
1345+
% [cvrPathLen, cvrDuration] = vistrack('measure_trials', get_str_(handles.editTrialSet));
13151346

13161347

13171348
% --- Executes on button press in btnSamplingDensity.
@@ -1354,44 +1385,7 @@ function btnListFiles_Callback(hObject, eventdata, handles)
13541385
% hObject handle to btnListFiles (see GCBO)
13551386
% eventdata reserved - to be defined in a future version of MATLAB
13561387
% handles structure with handles and user data (see GUIDATA)
1357-
1358-
S_trialset = file2struct(get_str_(handles.editTrialSet));
1359-
[csFiles_Track, csDir_trial] = find_files_(S_trialset.vcDir, '*_Track.mat');
1360-
1361-
fprintf('\n[Folders]\n');
1362-
disp(csDir_trial');
1363-
1364-
csFiles_Track = find_files_(csDir_trial, '*_Track.mat');
1365-
fprintf('\n[Files]\n');
1366-
disp(csFiles_Track')
1367-
msgbox(csDir_trial', 'Directories');
1368-
% msgbox(csFiles', 'Files');
1369-
1370-
1371-
function [csFiles, csDir] = find_files_(csDir, vcFile)
1372-
if ischar(csDir)
1373-
if any(csDir=='*')
1374-
csDir = find_dir_(csDir);
1375-
else
1376-
csDir = {csDir};
1377-
end
1378-
end
1379-
csFiles = {};
1380-
for iDir=1:numel(csDir)
1381-
S_dir_ = dir(fullfile(csDir{iDir}, vcFile));
1382-
csFiles_ = cellfun(@(x,y)fullfile(x,y), {S_dir_.folder}, {S_dir_.name}, 'UniformOutput', 0);
1383-
csFiles = [csFiles, csFiles_];
1384-
end %for
1385-
1386-
1387-
function csDir = find_dir_(vcDir)
1388-
S_dir = dir(vcDir);
1389-
csDir = {S_dir.name};
1390-
csFolder = {S_dir.folder};
1391-
1392-
csDir_ = csDir([S_dir.isdir]);
1393-
csFolder = csFolder([S_dir.isdir]);
1394-
csDir = cellfun(@(x,y)fullfile(x,y), csFolder, csDir_, 'UniformOutput', 0);
1388+
vistrack('trialset-list', get_str_(handles.editTrialSet));
13951389

13961390

13971391
function vc = get_str_(hObj)
@@ -1444,13 +1438,16 @@ function pushbutton70_Callback(hObject, eventdata, handles)
14441438
% handles structure with handles and user data (see GUIDATA)
14451439

14461440

1447-
function [FLIM, TC, img1, img00] = mov_flim_(vidobj, nFrames_skip)
1448-
if nargin<2, nFrames_skip = []; end % skip every 10 frames
1449-
if isempty(nFrames_skip), nFrames_skip = 75; end
1441+
function [FLIM, TC, img1, img00] = mov_flim_(vidobj, nFrames_load)
1442+
if nargin<2, nFrames_load = 300; end % skip every 10 frames
1443+
% if isempty(nFrames_skip), nFrames_skip = 75; end
14501444
warning off;
14511445
nFrames = vidobj.NumberOfFrames;
1446+
% nFrames_skip = floor(nFrames / nFrames_load);
14521447
TC = linspace(0, vidobj.Duration, nFrames);
1453-
viF = 1:nFrames_skip:nFrames;
1448+
% viF = 1:nFrames_skip:nFrames;
1449+
viF = unique(round(linspace(1, nFrames, nFrames_load)));
1450+
% viF = 1:nFrames_load; % much faster to load
14541451
tmr = read_(vidobj, viF);
14551452

14561453
% rough scan
@@ -1489,16 +1486,12 @@ function close_(h)
14891486

14901487

14911488
function tmr = read_(vidobj, viF)
1492-
h=msgbox('Loading video...');
1493-
tmr = zeros(vidobj.Height, vidobj.Width, numel(viF), 'uint8');
1494-
for iF1=1:numel(viF)
1495-
img = read(vidobj, viF(iF1));
1496-
tmr(:,:,iF1) = img(:,:,1);
1497-
end
1489+
h=msgbox('Loading video... (this will close automatically)'); drawnow;
1490+
tmr = vid_read(vidobj, viF);
14981491
close_(h);
14991492

15001493

1501-
function S_save = copyStruct_(handles, csField)
1494+
function S_save = struct_copy_(handles, csField)
15021495
for i=1:numel(csField)
15031496
try
15041497
S_save.(csField{i}) = handles.(csField{i});
@@ -1524,3 +1517,58 @@ function pushbutton74_Callback(hObject, eventdata, handles)
15241517
% hObject handle to pushbutton74 (see GCBO)
15251518
% eventdata reserved - to be defined in a future version of MATLAB
15261519
% handles structure with handles and user data (see GUIDATA)
1520+
1521+
1522+
% --- Executes on button press in btnSummary.
1523+
function btnSummary_Callback(hObject, eventdata, handles)
1524+
% hObject handle to btnSummary (see GCBO)
1525+
% eventdata reserved - to be defined in a future version of MATLAB
1526+
% handles structure with handles and user data (see GUIDATA)
1527+
csMsg = vistrack('summary', handles);
1528+
disp_cs_(csMsg);
1529+
msgbox(csMsg);
1530+
1531+
1532+
% --- Executes on button press in btnExport.
1533+
function btnExport_Callback(hObject, eventdata, handles)
1534+
% hObject handle to btnExport (see GCBO)
1535+
% eventdata reserved - to be defined in a future version of MATLAB
1536+
% handles structure with handles and user data (see GUIDATA)
1537+
vistrack('export', handles);
1538+
1539+
1540+
%--------------------------------------------------------------------------
1541+
% display cell string
1542+
function disp_cs_(cs)
1543+
cellfun(@(s)fprintf('%s\n',s), cs);
1544+
1545+
1546+
%--------------------------------------------------------------------------
1547+
% Retreive full path of a file
1548+
function vcFile_full = fullpath_(vcFile)
1549+
S_dir = dir(vcFile);
1550+
if numel(S_dir)~=1, vcFile_full = vcFile; return ;end
1551+
vcFile_full = fullfile(S_dir.folder, S_dir.name);
1552+
1553+
1554+
1555+
%--------------------------------------------------------------------------
1556+
% 7/20/2018 Copied from jrc3.m
1557+
% If field doesn't exist copy empty
1558+
function P = struct_merge_(P, P1, csNames)
1559+
% Merge second struct to first one
1560+
% P = struct_merge_(P, P_append)
1561+
% P = struct_merge_(P, P_append, var_list) : only update list of variable names
1562+
if isempty(P), P=P1; return; end % P can be empty
1563+
if isempty(P1), return; end
1564+
if nargin<3, csNames = fieldnames(P1); end
1565+
if ischar(csNames), csNames = {csNames}; end
1566+
1567+
for iField = 1:numel(csNames)
1568+
vcName_ = csNames{iField};
1569+
if isfield(P1, vcName_)
1570+
P.(vcName_) = P1.(vcName_);
1571+
else
1572+
P.(vcName_) = [];
1573+
end
1574+
end

LOADSETTINGS.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
end
66
catch
77
eval('settings_vistrack');
8-
end
8+
end
9+
10+
% Default values
11+
if exist('REPLAY_STEP', 'var') ~= 1, REPLAY_STEP = 4; end

calcESAC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
try
1515
ADC_ESAC = load(fname_esac);
1616
catch
17-
disp(lasterr);
17+
disp('EODA not saved.');
1818
ESAC = [];
1919
return;
2020
end

change_log.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Visual Tracker (vistrack) change log
2-
James Jun, Maler Lab, 2018/7/10
2+
James Jun, Maler Lab
3+
4+
[v0.1.7, 7/23/2018]
5+
Added "Summary" button in GUI
6+
Added "Export" button in GUI
7+
Robust video loading, number of frames calculated 3 times and max is taken.
8+
Updated "List Files" button for Trialset
9+
Added "Learning Curve" button for Trialset
10+
Settings box now displays new lines
11+
Faster video loading (~2x, requires a "Distrib_Computing_Toolbox")
312

413
[v0.1.6]
514
Added .trialset file loading

detectBlink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
end
2626
end
2727

28-
h=msgbox('Loading... (this will close automatically)');
28+
h=msgbox('Loading... (this will close automatically)', 'detect LED blink'); drawnow;
2929
trImg = read(handles.vidobj, FLIM1);
3030
trImg = squeeze(trImg(:,:,1,:));
3131
try close(h); catch, end;

example.trialset

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

2-
vcFile_track = 'D:\Aida\2014b_ShuffleCue\*_Track.mat';
2+
vcDir = 'G:\JunSpatial_Simone\Cue\';
33
csAnimals = {'A','B','C','D'};
4-
fProbeTrial = 0;
54
csDir_excl = {};
6-
csFile_excl = {};
5+
csFile_excl = {};
6+
viEarly_trial = 1:2;
7+
viLate_trial = 7:11;
8+
9+
% vcFile_xls = 'G:\JunSpatial_Simone\MATLAB analysis track sheet.xls';

0 commit comments

Comments
 (0)