2222
2323% Edit the above text to modify the response to help GUI
2424
25- % Last Modified by GUIDE v2.5 23 -Jul-2018 16:44:51
25+ % Last Modified by GUIDE v2.5 24 -Jul-2018 11:57:00
2626
2727% Begin initialization code - DO NOT EDIT
2828gui_Singleton = 1;
@@ -62,10 +62,7 @@ function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
6262
6363[vcVer, vcVer_date] = version_();
6464set(handles.textVer, 'String', sprintf('%s (%s) James Jun', vcVer, vcVer_date));
65-
66- if ~exist('.git', 'dir') ~= 7
67- set(handles.btnUpdate, 'Enable', 'off');
68- end
65+ set(handles.btnUpdate, 'Enable', ifeq_(exist_dir_('.git'), 'on', 'off'));
6966
7067% Update handles structure
7168guidata(hObject, handles);
@@ -133,6 +130,7 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
133130end
134131handles.vidFname = vidFname;
135132buttons_off_(handles);
133+ clear_cache_();
136134
137135% Set result field
138136vcFile_out = subsFileExt_(vidFname, '_Track.mat');
@@ -158,7 +156,7 @@ function btnLoadVideo_Callback(hObject, eventdata, handles)
158156
159157try
160158 set(handles.edit1, 'String', handles.vidFname);
161- h = msgbox('Loading... (this will close automatically)');
159+ h = msgbox('Loading... (this will close automatically)', 'modal' );
162160% handles.vidobj = VideoReader(handles.vidFname);
163161 handles.vidobj = vistrack('VideoReader', vidFname);
164162 fprintf('Video file info: %s\n', handles.vidFname);
@@ -535,35 +533,11 @@ function btnPreview_Callback(hObject, eventdata, handles)
535533[WINPOS, ~] = getBoundingBoxPos(handles.xy_init, size(img0), winlen*[1 1]);
536534img = handles.img1(WINPOS(3):WINPOS(4), WINPOS(1):WINPOS(2), :);
537535img0c = img0(WINPOS(3):WINPOS(4), WINPOS(1):WINPOS(2), :);
538- % img00c = handles.img00(WINPOS(3):WINPOS(4), WINPOS(1):WINPOS(2));
539-
540- % dimg = uint8(img0c - img);
541536dimg = uint8_diff(img0c, img, 0);
542- % dimg = uint8(mean(single(img0c) - single(img),3));
543- % dimg = uint8(sum(img0c - img, 3));
544- % dimg = uint8(mean(single(img) - single(img0c), 3)/3);
545- % dimg = uint8(abs(mean(single(img0c) - single(img), 3)/3));
546-
547- % absimg = imabsdiff(handles.img00, handles.img1);
548- % absimg(~handles.MASK) = 0;
549- % absimg = absimg(WINPOS(3):WINPOS(4), WINPOS(1):WINPOS(2));
550- % figure; subplot 121; imagesc(absimg); title('absdiff');
551- % subplot 122; imagesc(dimg); title('diff');
552- % return;
553-
554537BW = imdilate(bwmorph((dimg > IM_THRESH), 'clean', inf), SE);
555538BW = imfill(BW, 'holes');
556539BW = imclearborder(BW);
557540
558- % dimg1 = dimg;
559- % dimg1(bwperim(BW)) = 256;
560- % imgabs = im(handles.img00, handles.img1);
561- % imgabs(~handles.MASK) = 0;
562- % figure; imagesc(imgabs);
563- % figure; imagesc(dimg1);
564- % return;
565-
566- % [BW, AreaTarget] = bwgetlargestblob(BW);
567541regions = regionprops(BW, {'Area', 'Centroid', 'Orientation', 'FilledImage', 'BoundingBox'});
568542if numel(regions)>1
569543 L = bwlabel(BW, 8);
@@ -610,7 +584,7 @@ function btnPreview_Callback(hObject, eventdata, handles)
610584imagesc(img4, INTENSITY_LIM);
611585axis equal; axis tight;
612586set(gca, {'XTick', 'YTick'}, {[],[]});
613- title ('4. Superimposed');
587+ title_ ('4. Superimposed (if incorrect, lower "IM_THRESH") ');
614588colormap gray;
615589
616590
@@ -861,7 +835,7 @@ function btnMovOut_Callback(hObject, eventdata, handles)
861835%colorbar
862836plotColorbar(size(handles.img0), vrRateSrt, vrQuantSrt);
863837EODR1 = EODR(TEOD > TLIM(1) & TEOD < TLIM(2));
864- RLIM = [quantile (EODR1, .001), quantile (EODR1, .999)];
838+ RLIM = [quantile_ (EODR1, .001), quantile_ (EODR1, .999)];
865839htext = [];
866840vhChevron = [];
867841for iframe=1:nframes
@@ -1156,7 +1130,7 @@ function btnReplay_Callback(hObject, eventdata, handles)
11561130%setup fig
11571131timer1 = timer('Period', 1/15, 'ExecutionMode', 'fixedRate', 'TasksToExecute', inf);
11581132hFig = figure('NumberTitle', 'off', 'Name', ...
1159- '[H]elp; [L/R/U/D]; SPACEBAR:Pause; [F]lip; [C]ut upto here');
1133+ '[H]elp; (Sft)+ [L/R/U/D]; SPACEBAR:Pause; [F]lip; [C]ut upto here; [G]oto Frame ');
11601134hImg = imshow(imadjust(MOV(:,:,1))); hold on;
11611135iFrame = 1;
11621136XC = mrXC(iFrame,:);
@@ -1292,7 +1266,7 @@ function btnUpdate_Callback(hObject, eventdata, handles)
12921266% eventdata reserved - to be defined in a future version of MATLAB
12931267% handles structure with handles and user data (see GUIDATA)
12941268vistrack('update');
1295- msgbox('Update successful, please restart ');
1269+ msgbox('Update successful, Restart the app ');
12961270
12971271
12981272%--------------------------------------------------------------------------
@@ -1396,11 +1370,12 @@ function btnListFiles_Callback(hObject, eventdata, handles)
13961370end
13971371
13981372
1399- % --- Executes on button press in pushbutton65 .
1400- function pushbutton65_Callback (hObject, eventdata, handles)
1401- % hObject handle to pushbutton65 (see GCBO)
1373+ % --- Executes on button press in btnBarPlots .
1374+ function btnBarPlots_Callback (hObject, eventdata, handles)
1375+ % hObject handle to btnBarPlots (see GCBO)
14021376% eventdata reserved - to be defined in a future version of MATLAB
14031377% handles structure with handles and user data (see GUIDATA)
1378+ vistrack('trialset-barplots', get_str_(handles.editTrialSet));
14041379
14051380
14061381% --- Executes on button press in pushbutton66.
@@ -1439,7 +1414,13 @@ function pushbutton70_Callback(hObject, eventdata, handles)
14391414
14401415
14411416function [FLIM, TC, img1, img00] = mov_flim_(vidobj, nFrames_load)
1417+ % mov_flim_(): clear cache
1418+
1419+ persistent csAns1 csAns2 csAns3 mov1
1420+ if nargin==0, [csAns1, csAns2, csAns3] = deal([]); return; end %clear cache
1421+
14421422if nargin<2, nFrames_load = 300; end % skip every 10 frames
1423+
14431424% if isempty(nFrames_skip), nFrames_skip = 75; end
14441425warning off;
14451426nFrames = vidobj.NumberOfFrames;
@@ -1448,39 +1429,49 @@ function pushbutton70_Callback(hObject, eventdata, handles)
14481429% viF = 1:nFrames_skip:nFrames;
14491430viF = unique(round(linspace(1, nFrames, nFrames_load)));
14501431% viF = 1:nFrames_load; % much faster to load
1451- tmr = read_(vidobj, viF);
1432+ if isempty(mov1)
1433+ mov1 = mov_shrink_(read_(vidobj, viF), 2);
1434+ end
14521435
14531436% rough scan
1454- implay(tmr );
1437+ implay(mov1 );
14551438uiwait(msgbox('Find the first and last frame to track, and close the movie'));
1456- csAns = inputdlg({'First frame', 'Last frame'}, 'Get frames', 1, ...
1457- {'1', sprintf('%d', numel(viF))});
1439+ if isempty(csAns1), csAns1 = {'1', sprintf('%d', numel(viF))}; end
1440+ csAns = inputdlg({'First frame', 'Last frame'}, 'Get frames', 1, csAns1);
1441+ csAns1 = csAns;
14581442frame_first = viF(str2num(csAns{1}));
14591443frame_last = viF(str2num(csAns{2}));
1444+ fprintf('#1: First frame: %s; Last frame: %s\n', csAns{1}, csAns{2});
14601445
14611446% Find first frame to track
14621447viF_first = trim_(frame_first + (-150:149), 1, nFrames);
14631448tmr = read_(vidobj, viF_first);
1464- implay(tmr);
1449+ implay(mov_shrink_( tmr, 2) );
14651450uiwait(msgbox('Find the first frame to track and background, and close the movie'));
1466- csAns = inputdlg({'First frame', 'Background frame'}, 'Get frames', 1, ...
1467- {'1', num2str(numel(viF_first))});
1451+ if isempty(csAns2), csAns2 = {'1', num2str(numel(viF_first))}; end
1452+ csAns = inputdlg({'First frame', 'Background frame'}, 'Get frames', 1, csAns2);
1453+ csAns2 = csAns;
14681454img1 = tmr(:,:,str2num(csAns{1}));
14691455img00 = tmr(:,:,str2num(csAns{2}));
14701456frame_first = viF_first(str2num(csAns{1}));
1457+ fprintf('#2: First frame: %s; Background frame: %s\n', csAns{1}, csAns{2});
14711458
14721459% Find last frame to track
14731460viF_last = trim_(frame_last + (-150:149), 1, nFrames);
14741461tmr = read_(vidobj, viF_last);
1475- implay(tmr);
1462+ implay(mov_shrink_( tmr, 2) );
14761463uiwait(msgbox('Find the last frame to track, and close the movie'));
1477- csAns = inputdlg({'Last frame'}, 'Get frames', 1, ...
1478- {'1'});
1464+ iFrame3 = ceil(numel(viF_last)/2);
1465+ if isempty(csAns3), csAns3 = {num2str(iFrame3)}; end
1466+ csAns = inputdlg({'Last frame'}, 'Get frames', 1, csAns3);
1467+ csAns3 = csAns;
14791468frame_last = viF_last(str2num(csAns{1}));
1469+ fprintf('#3: Last frame: %s\n', csAns{1});
14801470
14811471FLIM = [frame_first, frame_last];
14821472TC = TC(frame_first:frame_last);
14831473
1474+
14841475function close_(h)
14851476try close(h); catch; end
14861477
@@ -1572,3 +1563,52 @@ function disp_cs_(cs)
15721563 P.(vcName_) = [];
15731564 end
15741565end
1566+
1567+
1568+ %--------------------------------------------------------------------------
1569+ % 7/24/2018 JJJ: Copied from jrc3.m
1570+ function flag = exist_dir_(vcDir)
1571+ if isempty(vcDir)
1572+ flag = 0;
1573+ else
1574+ flag = exist(vcDir, 'dir') == 7;
1575+ end
1576+
1577+
1578+ %--------------------------------------------------------------------------
1579+ % 7/24/2018: Copied from jrc3.m
1580+ function flag = key_modifier_(event, vcKey)
1581+ % Check for shift, alt, ctrl press
1582+ try
1583+ flag = any(strcmpi(event.Modifier, vcKey));
1584+ catch
1585+ flag = 0;
1586+ end
1587+
1588+
1589+ %--------------------------------------------------------------------------
1590+ % 7/24/2018: Copied from jrc3.m
1591+ function out = ifeq_(if_, true_, false_)
1592+ if (if_)
1593+ out = true_;
1594+ else
1595+ out = false_;
1596+ end
1597+
1598+
1599+ %--------------------------------------------------------------------------
1600+ % 7/24/2018 JJJ: Clear persistent memories
1601+ function clear_cache_()
1602+ mov_flim_(); % clear cache;
1603+
1604+
1605+ %--------------------------------------------------------------------------
1606+ % 7/24/2018 JJJ: resize movie by a scale factor
1607+ function mov = mov_shrink_(mov, nSkip)
1608+ if nSkip==1, return; end
1609+ mov = mov(1:nSkip:end, 1:nSkip:end, :);
1610+
1611+
1612+ %--------------------------------------------------------------------------
1613+ function hTItle = title_(vc)
1614+ hTItle = title(vc, 'Interpreter', 'none');
0 commit comments