-
Notifications
You must be signed in to change notification settings - Fork 0
/
etGUI.m
731 lines (595 loc) · 27.9 KB
/
etGUI.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
function varargout = etGUI(varargin)
% ETGUI MATLAB code for etGUI.fig
% ETGUI, by itself, creates a new ETGUI or raises the existing
% singleton*.
%
% H = ETGUI returns the handle to a new ETGUI or the handle to
% the existing singleton*.
%
% ETGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ETGUI.M with the given input arguments.
%
% ETGUI('Property','Value',...) creates a new ETGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before etGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to etGUI_OpeningFcn via varargin.
%
% *See GUI editPreferences 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 etGUI
% Last Modified by GUIDE v2.5 16-May-2017 17:49:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @etGUI_OpeningFcn, ...
'gui_OutputFcn', @etGUI_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 etGUI is made visible.
function etGUI_OpeningFcn(hObject, eventdata, 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 etGUI (see VARARGIN)
% let's turn off these useless and annoying warnings off
warning('off', 'MATLAB:nargchk:deprecated')
set(hObject, 'CloseRequestFcn', @close_etGUI);
set(hObject, 'WindowKeyPressFcn', @processKeyPress);
hObject.Resize = 'on';
handles.Axes.Visible = 'off';
handles.OriginalRadio.Value = 1;
handles.FilterSizeEdit.Value = 2;
handles.FilterSizeEdit.String = '2';
handles.PlotPush.Enable = 'on';
handles.AutoPush.Enable = 'off';
handles.CenterCheck.Value = false;
handles.EdgeCheck.Value = false;
handles.EllipseCheck.Value = true;
handles.BlinkCheck.Value = true;
handles.ROICheck.Value = false;
handles.CropCheck.Value = false;
handles.fileSave.Enable = 'off';
handles.editPreferences.Enable = 'off';
handles.FilenameText.Position = handles.FilenameText.Position +...
[-25 0 50 1];
handles.OverwriteCheck.String = 'Reanalyze and overwrite?';
handles = assignTooltips(handles);
pos = handles.PreviewToggle.Position;
tt = uicontrol(hObject, 'Style', 'Text');
tt.Units = 'characters';
tt.Position = pos + [-30 -2 10 1];
tt.String = 'Ctrl+S will overwrite the results for this frame';
tt.FontWeight = 'bold';
% handles.CurrentFolder = 'C:\DATA\';
pars = loadPars;
handles.CurrentFolder = pars.initFolder;
handles.localTempFileName = pars.localTempFileName;
% Choose default command line output for etGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes etGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = etGUI_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
varargout{1} = handles.output;
% --- Executes on slider movement.
function FrameSlider_Callback(hObject, eventdata, handles)
% hObject handle to FrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
hObject.Value = round(hObject.Value);
handles.iFrame = hObject.Value;
handles.CurrentFrame = read(handles.vr, handles.iFrame);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function FrameSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to FrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in AutoPush.
function AutoPush_Callback(hObject, eventdata, handles)
% hObject handle to AutoPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on slider movement.
function MaxSlider_Callback(hObject, eventdata, handles)
% hObject handle to MaxSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
hObject.Value = max(hObject.Value, handles.MinSlider.Value+1);
updateFigure(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function MaxSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to MaxSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function MinSlider_Callback(hObject, eventdata, handles)
% hObject handle to MinSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
hObject.Value = min(hObject.Value, handles.MaxSlider.Value-1);
updateFigure(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function MinSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to MinSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function ThresholdSlider_Callback(hObject, eventdata, handles)
% hObject handle to ThresholdSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ThresholdText.String = sprintf('%3.1f', hObject.Value);
updateFigure(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function ThresholdSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to ThresholdSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in CenterCheck.
function CenterCheck_Callback(hObject, eventdata, handles)
% hObject handle to CenterCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of CenterCheck
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in EdgeCheck.
function EdgeCheck_Callback(hObject, eventdata, handles)
% hObject handle to EdgeCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of EdgeCheck
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in EllipseCheck.
function EllipseCheck_Callback(hObject, eventdata, handles)
% hObject handle to EllipseCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of EllipseCheck
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in ROICheck.
function ROICheck_Callback(hObject, eventdata, handles)
% hObject handle to ROICheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ROICheck
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in CropCheck.
function CropCheck_Callback(hObject, eventdata, handles)
% hObject handle to CropCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of CropCheck
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in RunToggle.
function RunToggle_Callback(hObject, eventdata, handles)
% hObject handle to RunToggle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disableAll(handles.figure1);
hObject.Enable = 'on';
handles.PlotPush.Enable = 'on';
handles = runAnalysis(hObject, eventdata, handles);
enableAll(handles.figure1);
handles = updateBlinks(handles);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
function FilterSizeEdit_Callback(hObject, eventdata, handles)
% hObject handle to FilterSizeEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of FilterSizeEdit as text
% str2double(get(hObject,'String')) returns contents of FilterSizeEdit as a double
num = str2double(hObject.String);
if ~isnan(num)
num = min(max(num, 0.1), 100);
hObject.Value = num;
hObject.String = num2str(hObject.Value);
else
hObject.String = num2str(hObject.Value);
end
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function FilterSizeEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to FilterSizeEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in PreviewToggle.
function PreviewToggle_Callback(hObject, eventdata, handles)
% hObject handle to PreviewToggle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = handles;
if hObject.Value
handles.ROIPush.Enable = 'off';
handles.BlinkROIPush.Enable = 'off';
handles.RunToggle.Enable = 'off';
handles.AutoPush.Enable = 'off';
handles.ReplayToggle.Enable = 'off';
handles.ReplaySlider.Enable = 'off';
hObject.String = 'Stop';
end
while (hObject.Value) && h.iFrame<h.vr.NumberOfFrames
h.iFrame = h.iFrame + 1;
h.CurrentFrame = read(h.vr, [h.iFrame, h.iFrame]);
updateFigure(hObject, eventdata, h);
guidata(hObject, h);
end
hObject.Value = 0;
hObject.String = 'Preview';
enableAll(handles.figure1);
guidata(hObject, h);
% --- Executes on button press in PlotPush.
function PlotPush_Callback(hObject, eventdata, handles)
% hObject handle to PlotPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = plotTraces(hObject, eventdata, handles);
guidata(hObject, handles);
function GotoEdit_Callback(hObject, eventdata, handles)
% hObject handle to GotoEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of GotoEdit as text
% str2double(get(hObject,'String')) returns contents of GotoEdit as a double
num = str2double(hObject.String);
if ~isnan(num)
num = min(max(round(num), 1), handles.vr.NumberOfFrames);
hObject.Value = num;
hObject.String = num2str(hObject.Value);
else
hObject.String = num2str(hObject.Value);
end
handles.iFrame = hObject.Value;
handles.CurrentFrame = read(handles.vr, handles.iFrame);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function GotoEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to GotoEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in ROIPush.
function ROIPush_Callback(hObject, eventdata, handles)
% hObject handle to ROIPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disableAll(handles.figure1);
hRect = imrect(handles.Axes, handles.roi);
fcn = makeConstrainToRectFcn('imrect', [1 handles.vr.Width], [1 handles.vr.Height]);
setPositionConstraintFcn(hRect,fcn);
handles.roi = wait(hRect);
handles.roi = [ceil(handles.roi(1:2)), floor(handles.roi(3:4))];
handles.ROICheck.Value = 1;
enableAll(handles.figure1);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject handle to File (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function fileOpen_Callback(hObject, eventdata, handles)
% hObject handle to fileOpen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[handles, errFlag] = openfile(hObject, eventdata, handles);
if (errFlag == 0)
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
else
% do nothing,
% errFlag == -1 ==> no file was selected to be opened
end
% --------------------------------------------------------------------
function fileSave_Callback(hObject, eventdata, handles)
% hObject handle to fileSave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = handles;
results = h.results;
state = getCurrentState(h);
[~, fn, ~] = fileparts(h.FileName);
% the results are saved in the same folder as the video file
filename = fullfile(h.CurrentFolder, [fn, '_processed.mat']);
save(filename, 'results', 'state');
h.lastFileSaved = filename;
guidata(hObject, h);
% --------------------------------------------------------------------
function fileSaveAs_Callback(hObject, eventdata, handles)
% hObject handle to fileSaveAs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = fileSaveAs(hObject, eventdata, handles);
guidata(hObject, handles);
% --------------------------------------------------------------------
function fileLoad_Callback(hObject, eventdata, handles)
% hObject handle to fileLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[handles, errFlag] = fileLoad(hObject, eventdata, handles);
if errFlag == 0
guidata(hObject, handles);
updateFigure(hObject, eventdata, handles);
else
% do nothing, something went wrong, most likely no file was selected
end
% --------------------------------------------------------------------
function Edit_Callback(hObject, eventdata, handles)
% hObject handle to Edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function editPreferences_Callback(hObject, eventdata, handles)
% hObject handle to editPreferences (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on slider movement.
function FineFrameSlider_Callback(hObject, eventdata, handles)
% hObject handle to FineFrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
hObject.Value = round(hObject.Value);
handles.iFrame = hObject.Value;
handles.CurrentFrame = read(handles.vr, handles.iFrame);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function FineFrameSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to FineFrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in OriginalRadio.
function OriginalRadio_Callback(hObject, eventdata, handles)
% hObject handle to OriginalRadio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of OriginalRadio
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in FilteredRadio.
function FilteredRadio_Callback(hObject, eventdata, handles)
% hObject handle to FilteredRadio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of FilteredRadio
updateFigure(hObject, eventdata, handles);
% --- Executes on button press in BWRadio.
function BWRadio_Callback(hObject, eventdata, handles)
% hObject handle to BWRadio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of BWRadio
updateFigure(hObject, eventdata, handles);
function RangeEdit_Callback(hObject, eventdata, handles)
% hObject handle to RangeEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of RangeEdit as text
% str2double(get(hObject,'String')) returns contents of RangeEdit as a double
global frameRange
h = handles;
tmp = 1:h.vr.NumberOfFrames;
try
h.RangeEdit.Value = eval(sprintf('tmp(%s)', h.RangeEdit.String));
h.AnalysisStatusText.String = sprintf('1/%d\t xxx fps \thh:mm:ss left', length(h.RangeEdit.Value));
h.RangeEdit.BackgroundColor = 'green';
pause(0.2);
h.RangeEdit.BackgroundColor = 'white';
catch
h.RangeEdit.BackgroundColor = 'red';
end
if h.OverwriteCheck.Value
h.framesToAnalyze = h.RangeEdit.Value;
else
h.framesToAnalyze = setdiff(h.RangeEdit.Value, find(h.analyzedFrames));
end
h.AnalysisStatusText.String = sprintf('1/%d\t xxx fps \thh:mm:ss left', length(h.framesToAnalyze));
guidata(hObject, h);
% --- Executes during object creation, after setting all properties.
function RangeEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to RangeEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in OverwriteCheck.
function OverwriteCheck_Callback(hObject, eventdata, handles)
% hObject handle to OverwriteCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of OverwriteCheck
h = handles;
if hObject.Value
h.framesToAnalyze = h.RangeEdit.Value;
else
h.framesToAnalyze = setdiff(h.RangeEdit.Value, find(h.analyzedFrames));
end
h.AnalysisStatusText.String = sprintf('1/%d\t xxx fps \thh:mm:ss left', length(h.framesToAnalyze));
guidata(hObject, h);
% --- Executes on button press in ReplayToggle.
function ReplayToggle_Callback(hObject, eventdata, handles)
% hObject handle to ReplayToggle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ReplayToggle
h = handles;
if hObject.Value
h.ROIPush.Enable = 'off';
h.BlinkROIPush.Enable = 'off';
h.RunToggle.Enable = 'off';
h.AutoPush.Enable = 'off';
h.PreviewToggle.Enable = 'off';
h.FrameSlider.Enable = 'off';
h.FineFrameSlider.Enable = 'off';
hObject.BackgroundColor = 'green';
hObject.String = 'Stop';
drawnow;
end
framesToReplay = find(h.analyzedFrames);
% find a frame closest to the current one, which is analyzed
[~, iF] = min(abs(framesToReplay-h.iFrame));
while (hObject.Value) && ~isempty(iF) && iF<length(framesToReplay)
iF = iF + 1;
h.iFrame = framesToReplay(iF);
h.CurrentFrame = read(h.vr, h.iFrame);
updateFigure(hObject, eventdata, h);
h.ReplaySlider.Value = iF;
guidata(hObject, h);
end
hObject.Value = 0;
hObject.String = 'Replay';
hObject.BackgroundColor = [1 1 1]*0.94;
enableAll(h.figure1);
guidata(hObject, h);
% --- Executes on button press in BlinkROIPush.
function BlinkROIPush_Callback(hObject, eventdata, handles)
% hObject handle to BlinkROIPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disableAll(handles.figure1);
hRect = imrect(handles.Axes, handles.blinkRoi);
fcn = makeConstrainToRectFcn('imrect', [1 handles.vr.Width], [1 handles.vr.Height]);
setPositionConstraintFcn(hRect,fcn);
handles.blinkRoi = wait(hRect);
handles.blinkRoi = [ceil(handles.blinkRoi(1:2)), floor(handles.blinkRoi(3:4))];
handles.BlinkCheck.Value = 1;
enableAll(handles.figure1);
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes on button press in BlinkCheck.
function BlinkCheck_Callback(hObject, eventdata, handles)
% hObject handle to BlinkCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of BlinkCheck
updateFigure(hObject, eventdata, handles);
% --- Executes on slider movement.
function ReplaySlider_Callback(hObject, eventdata, handles)
% hObject handle to ReplaySlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
hObject.Value = round(hObject.Value);
idx = find(handles.analyzedFrames);
handles.iFrame = idx(hObject.Value);
handles.CurrentFrame = read(handles.vr, handles.iFrame);
% call udateFigure() as if from the ReplayToggle Callback
updateFigure(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function ReplaySlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to ReplaySlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --------------------------------------------------------------------
function runBatch_Callback(hObject, eventdata, handles)
% hObject handle to runBatch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
etBatch(handles.figure1);
% --- Executes during object creation, after setting all properties.
function PlotPush_CreateFcn(hObject, eventdata, handles)
% hObject handle to PlotPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'ButtonDownFcn', @plotClick);
% --- Executes on button press in BlinksOnlyCheck.
function BlinksOnlyCheck_Callback(hObject, eventdata, handles)
% hObject handle to BlinksOnlyCheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of BlinksOnlyCheck
% --- Executes on button press in BlinkClassifierPush.
function BlinkClassifierPush_Callback(hObject, eventdata, handles)
% hObject handle to BlinkClassifierPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'plotHandles');
return;
end
disableAll(handles.figure1);
try
hPoly = impoly(handles.plotHandles.blinkAxes, handles.blinkClassifier);
handles.blinkClassifier = wait(hPoly);
delete(hPoly);
handles = updateBlinks(handles);
% updating handles here as well (for the case when the code crashes inside
% plotTraces and then never gets to the guidata() line)
guidata(hObject, handles);
handles = plotTraces(hObject, eventdata, handles);
guidata(hObject, handles);
catch
end
enableAll(handles.figure1);