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
2828gui_Singleton = 1;
@@ -56,7 +56,8 @@ function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
5656handles.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');
6061set(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.
7787function 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);
123133end
124134handles.vidFname = vidFname;
135+ buttons_off_(handles);
125136
126137% Set result field
127138vcFile_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', '');
146157end
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)
186202end
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
190214function 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
10931111h = 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
11001125try
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));
11041127catch
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);
11071129end
11081130close_(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)
12141236if isempty(vcFile)
12151237 flag = 0;
12161238else
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
12181245end
12191246if 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
12891316vcFile_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
12941325set(handles.editTrialSet, 'String', vcFile_trialset);
12951326set(handles.panelTrialSet, 'Visible', 'on');
12961327edit(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
13971391function 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
14501444warning off;
14511445nFrames = vidobj.NumberOfFrames;
1446+ % nFrames_skip = floor(nFrames / nFrames_load);
14521447TC = 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
14541451tmr = read_(vidobj, viF);
14551452
14561453% rough scan
@@ -1489,16 +1486,12 @@ function close_(h)
14891486
14901487
14911488function 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);
14981491close_(h);
14991492
15001493
1501- function S_save = copyStruct_ (handles, csField)
1494+ function S_save = struct_copy_ (handles, csField)
15021495for 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
0 commit comments