-
Notifications
You must be signed in to change notification settings - Fork 7
/
DLTdv5.m
4464 lines (3753 loc) · 151 KB
/
DLTdv5.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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [] = DLTdv5(varargin)
% function [] = DLTdv5()
%
% DLTdv is a digitizing environment designed to acquire
% 3D coordinates from 2-7 video sources calibrated via a set of
% DLT coefficients. It can also digitize one or more video streams
% without DLT coefficients.
%
% Features:
% *Simultaneous viewing of up to 7 video files
% *Displays line of least residual given a point on one of the
% images in 3D mode
% *Automatic tracking of markers or features from frame to frame
% *Kalman and Double Exponential predictors to enhance auto-tracking
% *Display and track color or grayscale videos
% *Change frame sync of the different video streams
% *Change the gamma of the videos
% *Load and modify previously digitized trials
%
% See the associated RTF or PDF document for complete usage information,
% see the online video tutorials for a basic introduction.
%
% Version 1 - Tyson Hedrick 8/1/04
% Version 2 - Tyson Hedrick 8/4/05
% Version 3 - Tyson Hedrick 3/1/08
% Version 5 - Tyson Hedrick 6/14/10
% 2014-10-16 - updated for compatibility with r2014b new graphics
% environment, checked for backward compatibility with r2013a and r2008b
% 2015-04-15 - fix problems relating to mp4 timebase
% 2016-08-18 - fix missing semicolon (Delyle Polet)
%% Function initialization
if nargin==0 % no inputs, just fix the path and run the gui
% check Matlab version and don't start if not >= 7. Many of the figure
% and gui controls changed in the 6.5 --> 7.0 jump and it is no longer
% possible to support the older versions.
v=version;
if str2double(v(1:3))<7
beep
disp('DLTdv5 requires MATLAB version 7 or later.')
return
end
% check to make sure that mmreader is available
if exist('mmreader')~=2 && exist('VideoReader')~=2
beep
disp('DLTdv5 requires mmreader or VideoReader to read AVIs or other')
disp('standard video files. Those functions are not available to you')
disp('so you will only be able to read uncompressed Phantom cine and')
disp('IDT mrf high speed camera files.')
disp('Check the Mathworks online documentation to learn about mmreader')
disp('and VideoReader. Use DLTdv4 if you have an older MATLAB version')
disp('that has the aviread function.')
end
% check to make sure we were called with the appropriate name
if strcmpi(mfilename,'DLTdv5')==0
beep
disp('Error: This program must be named "DLTdv5.m" to function properly.')
return
end
% check to see if we are in the path, add us if we are not
dltloc=which('DLTdv5');
if ispc, p1=lower(path); else p1=path; end % current path
% DLTdv5 directory
dlttrim=dltloc(1:end-9);
if ispc, dlttrim=lower(dlttrim); end
% create an index of path separators, including the start and end if
% necessary
idx=find(p1==pathsep);
if idx(end)~=numel(p1)
idx(end+1)=numel(p1)+1;
end
idx2(1)=0;
idx2(2:numel(idx)+1)=idx;
% loop through the path and see if dltloc matches it
for i=1:numel(idx2)-1
pstring=p1(idx2(i)+1:idx2(i+1)-1); % path segment
if strcmp(pstring,dlttrim)
inPath=1; % found a match
break
else
inPath=0;
end
end
if inPath==0 % didn't find a match
% add DLTdv5's directory to the end of the path
addpath(dlttrim,p1);
fprintf('Adding %s to the MATLAB search path \n',dlttrim)
end
call=99; % go creat the GUI if we didn't get any input arguments
elseif nargin==1 % assume a switchyard call but no data
call=varargin{1};
try
ud=getappdata(gcbo,'Userdata'); % get simple Userdata
h=ud.handles; % get the handles
uda=getappdata(h(1),'Userdata'); % get application data
h=uda.handles; % get complete handles
catch
ud=getappdata(get(gcbo,'parent'),'Userdata'); % get simple Userdata
h=ud.handles; % get the handles
uda=getappdata(h(1),'Userdata'); % get application data
h=uda.handles; % get complete handles
end
sp=get(h(32),'Value'); % get the selected point
elseif nargin==2 % assume a switchyard call and data
call=varargin{1};
uda=varargin{2};
h=uda.handles; % get complete handles
sp=get(h(32),'Value'); % get the selected point
elseif nargin==3 % switchyard call, data & subfunction specific data
call=varargin{1};
uda=varargin{2};
h=uda.handles; % get complete handles
sp=get(h(32),'Value'); % get the selected point
oData=varargin{3}; % store the misc. other variable in oData
else
disp('DLTdv5: incorrect number of input arguments')
return
end
% switchyard to handle updating & processing tasks for the figure
switch call
%% case 99 - GUI figure creation
case {99} % Initialize the GUI
fprintf('\n')
disp('DLTdv5 (updated August 18, 2016)')
fprintf('\n')
disp('Visit http://www.unc.edu/~thedrick/ for more information,')
disp('tutorials, sample data & updates to this program.')
fprintf('\n')
% layout parameters for controls window
top=40.23;
width=58;
h(1) = figure('Units','characters',... % control figure
'Color',[0.831 0.815 0.784]','Doublebuffer','on', ...
'IntegerHandle','off','MenuBar','none',...
'Name','DLTdv5 controls','NumberTitle','off',...
'Position',[10 10 width top],'Resize','off',...
'HandleVisibility','callback','Tag','figure1',...
'Userdata',[],'Visible','on','deletefcn','DLTdv5(13)',...
'interruptible','on');
h(29) = uicontrol('Parent',h(1),'Units','characters',... % Video frame
'Position',[3 26.2 51.5 8.0],'Style','frame','BackgroundColor',...
[0.568 0.784 1],'string','Points and auto-tracking');
h(30) = uicontrol('Parent',h(1),... % Points frame part 1
'Units','characters','Position',[3 top-28.73 51.5 14.3],'Style',...
'frame','BackgroundColor',[0.788 1 0.576],'string',...
'Points and auto-tracking');
uicontrol('Parent',h(1),'Units','characters',... % Points frame part 2
'Position',[3 top-39.23 31.5 12.5],'Style','frame',...
'BackgroundColor',[0.788 1 0.576],'string',...
'Points and auto-tracking');
uicontrol('Parent',h(1),... % blank string
'Units','characters','Position',[3.1 top-28.68 32.3 4.6],'Style',...
'text','BackgroundColor',[0.788 1 0.576],'string','');
uicontrol('Parent',h(1),'Units','characters',... % Points frame part 3
'Position',[23 top-39.23 31.5 2.8],'Style','frame',...
'BackgroundColor',[0.788 1 0.576],'string','bottom right');
uicontrol('Parent',h(1),... % blank string
'Units','characters','Position',[3.1 top-39.15 31.3 4.6],'Style',...
'text','BackgroundColor',[0.788 1 0.576],'string','');
h(5) = uicontrol('Parent',h(1),'Units','characters',... % frame slider
'Position',[7.2 top-13.23 44.2 1.2],'String',{ 'frame' },...
'Style','slider','Tag','slider2','Callback',...
'DLTdv5(1)','Enable','off');
h(6) = uicontrol('Parent',h(1),... % initialize button
'Units','characters','Position',[2.2 top-4.43 14 3],'String',...
'Initialize','Callback','DLTdv5(0)','ToolTipString', ...
'Load the videos and DLT specification','Tag','pushbutton1');
h(7) = uicontrol('Parent',h(1),... % Save data button
'Units','characters','Position',[21 top-2.73 14.4 1.8],'String',...
'Save Data','Tag','pushbutton3',...
'Callback','DLTdv5(5)','Enable','off');
% h(8) - frame number text box (see below)
% h(10) - unused
% h(11) - unused
% h(12) - color control check box, see below
h(18) = uicontrol('Parent',h(1),... % gamma control label
'Units','characters','BackgroundColor',[0.568 0.784 1],...
'HorizontalAlignment','left','Position',[7 top-8.03 20.4 1.3],...
'String','Video gamma','Style','text','Tag','text1');
uicontrol('Parent',h(1),... % color video control label
'Units','characters','BackgroundColor',[0.568 0.784 1],...
'HorizontalAlignment','left','Position',[37 top-8.03 17.0 1.3],...
'String','Display in color','Style','text','Tag','text1');
h(12)=uicontrol('Parent',h(1),... % Color display checkbox
'Units','characters','BackgroundColor',[0.568 0.784 1],...
'Position',[43 top-9.23 4 1],'Value',0,'Style','checkbox','Tag',...
'colorVideos','enable','off','Callback','DLTdv5(15)');
h(13) = uicontrol('Parent',h(1),... % video gamma slider
'Units','characters','Position',[7 top-9.23 28 1.3],'String',...
{ 'gamma' },'Style','slider','Tag','slider1','Min',.1','Max',...
2,'Value',1,'Callback','DLTdv5(1)', ...
'Enable','off', 'ToolTipString','Video Gamma slider');
h(14) = uicontrol('Parent',h(1),'Units','characters',... % quit button
'Position',[39.8 top-4.43 15.2 3],'String','Quit',...
'Tag','pushbutton4','Callback','DLTdv5(11)','enable','on');
% h(15-17) - unused
% h(18) - Gamma control label, see above
% h(19) - see below (add point button)
% h(20) - unused
uicontrol('Parent',h(1),... % frame slider label
'Units','characters','BackgroundColor',[0.568 0.784 1],...
'HorizontalAlignment','left','Position',[7 top-11.73 26.6 1.1],...
'String','Frame number:','Style','text','Tag','text6');
h(21) = uicontrol('Parent',h(1),... % frame slider label
'Units','characters','BackgroundColor',[0.568 0.784 1],...
'HorizontalAlignment','left','Position',[35 top-11.73 6.6 1.1],...
'String','/NaN','Style','text','Tag','text6');
h(8) = uicontrol('Parent',h(1),... % frame text box
'Units','characters','BackgroundColor',[1 1 1],'Position',...
[24 top-11.73 10 1.5],'String','0','Style','edit','Tag','edit3',...
'Callback','DLTdv5(7)','enable','off');
h(22) = uicontrol('Parent',h(1),... % load previous data button
'Units','characters','Position',[21 top-5.23 14.4 1.7],'String',...
'Load Data','Tag','pushbutton5','enable','off','Callback',...
'DLTdv5(6)');
h(23) = uicontrol('Parent',h(1),... % Autotrack search width label
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'HorizontalAlignment','left','Position',[7 top-24.03 26.6 1.3],...
'String','Autotrack search area size','Style','text',...
'Tag','text15');
h(25) = uicontrol('Parent',h(1),... % Autotrack threshold label
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'HorizontalAlignment','left','Position',[7 top-27.13 26.6 1.3],...
'String','Autotrack threshold','Style','text',...
'Tag','text16');
h(27) = uicontrol('Parent',h(1),... % Autotrack fit
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'HorizontalAlignment','left','Position',[7 top-25.23 26.6 1.3],...
'String','Autotrack fit: --','Style','text','Tag','text17');
h(31) = uicontrol('Parent',h(1),... % Current point label
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'HorizontalAlignment','left','Position',[7 top-17.23 14.2 1.3],...
'String','Current point','Style','text','Tag','text13');
h(32) = uicontrol(... % Current point pull-down menu
'Parent',h(1),'Units','characters','Position',...
[21.6 top-17.33 10 1.6],'String',' 1','Style','popupmenu',...
'Value',1,'Tag','popupmenu1','Enable','off','Callback',...
'DLTdv5(1)');
h(19) = uicontrol('Parent',h(1),... % add-a-point button
'Units','characters','Position',[33.2 top-17.33 16 1.6],'String',...
'Add a point','Callback','DLTdv5(12)','ToolTipString', ...
'Add a point to the pull down menu','Tag','pushbutton1', ...
'enable','off');
h(33) = uicontrol('Parent',h(1),... % DLT residual
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'HorizontalAlignment','left','Position',[7 top-29.0 26.6 1.3],...
'String','DLT residual: --','Style','text','Tag','text18');
h(34) = uicontrol('Parent',h(1), ... % Autotrack mode label
'Units','characters','Position',[7 top-19.63 24.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Autotrack mode');
h(35) = uicontrol(... % Current point pull-down menu
'Parent',h(1),'Units','characters','Position',...
[24 top-19.48 20 1.6],'String',...
'off|auto-advance|semiautomatic|automatic|multi',...
'Style','popupmenu',...
'Value',1,'Tag','popupmenu1','Enable','off','Callback',...
'DLTdv5(1)');
%h(36) & h(37) are unused
h(38) = uicontrol('Parent',h(1),... % Autotrack search area size
'Units','characters','BackgroundColor',[1 1 1],'Position',...
[36.8 top-24.13 9.8 1.6],'String','9','Style','edit','Tag',...
'edit7','Callback','DLTdv5(9)','enable','off');
h(39) = uicontrol('Parent',h(1),... % Autotrack threshold
'Units','characters','BackgroundColor',[1 1 1],'Position', ...
[36.8 top-26.93 9.8 1.6],'String','9','Style','edit','Tag', ...
'edit8','Callback','DLTdv5(10)','enable','off');
% h(40) - h(43) unused
% h(50) - unused
h(51)=axes('Position',... % create autotrack image axis
[.63 .11 .30 .165],'XTickLabel','', ...
'YTickLabel','','Visible','on','Parent',h(1),'box','off');
c=(repmat((0:1/254:1)',1,3)); % grayscale color map
image('Parent',h(51),'Cdata',chex(1,21,21).*255, ...
'CDataMapping','direct'); % display the target image
colormap(h(51),c)
xlim(h(51),[1 21]);
ylim(h(51),[1 21]);
h(52)=uicontrol('Parent',h(1), ... % DLT visual feedback label
'Units','characters','Position',[7 top-34.63 24.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','DLT visual feedback');
h(53)=uicontrol('Parent',h(1),... % DLT visual feedback checkbox
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'Position',[29 top-34.33 4 1],'Value',1,'Style','checkbox','Tag',...
'DLTfeedbackbox','enable','off','Callback','DLTdv5(1)');
h(54)=uicontrol('Parent',h(1), ... % Centroid finding label
'Units','characters','Position',[7 top-38.53 24.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Find marker centroid');
h(55)=uicontrol('Parent',h(1),... % Centroid finding checkbox
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'Position',[29 top-38.2 4 1],'Value',0,'Style','checkbox','Tag',...
'findCentroidBox','enable','off','Callback','DLTdv5(14)');
h(56) = uicontrol('Parent',h(1), ... % Autotrack predictor mode label
'Units','characters','Position',[7 top-21.63 29.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Autotrack predictor');
predMenu={'extended Kalman','double exponential','1st order poly',...
'static point'};
h(57) = uicontrol(... % Autotrack predictor mode menu
'Parent',h(1),'Units','characters','Position',...
[30.2 top-21.63 20 1.6],'String',predMenu,'Style','popupmenu',...
'Value',1,'Tag','popupmenu2','Enable','off','Callback',...
'DLTdv5(1)');
h(58) = uicontrol('Parent',h(1), ... % Centroid color label
'Units','characters','Position',[34 top-38.53 14.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Color');
h(59) = uicontrol(... % Centroid color menu
'Parent',h(1),'Units','characters','Position',...
[42 top-38.43 11 1.6],'String',{'black','white'},'Style',...
'popupmenu','Value',1,'Tag','popupmenu3','Enable','off');
h(60) = uicontrol('Parent',h(1), ... % DLT threshold label
'Units','characters','Position',[9 top-30.83 19.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Threshold:');
h(61) = uicontrol('Parent',h(1),... % DLT residual threshold
'Units','characters','BackgroundColor',[1 1 1],'Position', ...
[21.8 top-30.8 9.8 1.6],'String','3','Style','edit','Tag','edit8',...
'Callback','DLTdv5(10)','enable','off');
h(62) = uicontrol('Parent',h(1), ... % Update all videos
'Units','characters','Position',[7 top-32.73 19.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Update all videos');
h(63)=uicontrol('Parent',h(1),... % Update all videos checkbox
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'Position',[29 top-32.6 4 1],'Value',1,'Style','checkbox','Tag',...
'updateVideos','enable','off');
h(64)=uicontrol('Parent',h(1), ... % 2D tracks label
'Units','characters','Position',[7 top-36.63 24.2 1.3],...
'BackgroundColor',[0.788 1 0.576],'HorizontalAlignment','left',...
'Style','text','String','Show 2D tracks');
h(65)=uicontrol('Parent',h(1),... % 2D tracks checkbox
'Units','characters','BackgroundColor',[0.788 1 0.576],...
'Position',[29 top-36.33 4 1],'Value',0,'Style','checkbox','Tag',...
'DLTfeedbackbox','enable','on','Callback','DLTdv5(1)');
ud.handles=h; % simple Userdata object
% for each handle set all handle info in Userdata
for i=1:numel(h)
setappdata(h(i),'Userdata',ud);
end
% Expanded userdata for the handle object
uda.handles=h;
uda.recentlysaved = true; % no data to save yet!
setappdata(h(1),'Userdata',uda);
% Make sure the GUI is onscreen
if exist('movegui')==2
movegui(h(1));
end
return
%% case 0 - Initialize button callback
case {0} % Initialize button press from the GUI
% ask the user how many videos to load
[uda.nvid,ok]=...
listdlg('PromptString','How many videos do you have?', ...
'SelectionMode','single','ListString',{'1','2','3','4','5','6',...
'7','8','9'}, 'Name', ...
'# of videos','listsize',[160 80]);
pause(0.1); % make sure that the listdlg executed (MATLAB bug)
if ok==0
disp('Initialization canceled, please try again.')
return
end
% create movie figures and axes
for i=1:uda.nvid
h(200+i) = figure('units','pixels', 'color',[0.83 0.82 0.78],...
'doublebuffer','on','KeyPressFcn','DLTdv5(2)','menubar','none',...
'Name',sprintf('Movie %.0f',i),'numbertitle','off',...
'handlevisibility','callback','tag',sprintf('movieFig%.0f',i),...
'Userdata',uda,'Visible','on','deletefcn','DLTdv5(13)',...
'pointer','cross','interruptible','on','position',...
[361+i*10 242-i*10 560 420]);
setappdata(h(200+i),'videoNumber',i);
if exist('movegui')==2 % make sure the figure is onscreen
movegui(h(200+i));
end
h(300+i) = axes('Position',[.01 .10 .99 .89],'XTickLabel','', ...
'YTickLabel','','ButtonDownFcn','DLTdv5(3)', ...
'Visible','off','Parent',h(200+i));
uicontrol('Parent',h(200+i),... % frame offset label
'Units','characters','BackgroundColor',[0.83 0.82 0.78],...
'HorizontalAlignment','right',...
'Position',[2 1 20 2],'String','Frame offset:',...
'Style','text','Tag','text4');
h(325+i) = uicontrol('Parent',h(200+i),... % frame offset box
'Units','characters','BackgroundColor',[1 1 1],'Position',...
[24 1.5 5 2],'String','0','Style','edit','Tag','edit2', ...
'Callback','DLTdv5(8)','enable','on');
h(350+i) = uicontrol('Parent',h(200+i),...
'Units','characters','BackgroundColor',[1 1 1],'Position',...
[30 1.5 20 2],'String','Horizontal mirror','Style','checkbox',...
'Tag','edit2','Callback','DLTdv5(17)','enable','on','visible','on');
h(400+i) = uicontrol('Parent',h(200+i),... % undistortion button
'Units','characters','BackgroundColor',[1 1 1],'Position',...
[51 1.5 20 2],'String','Set Undistortion profile','style','pushbutton',...
'Tag','UndistortionButton','Callback','DLTdv5(18)','enable','on',...
'Visible','on');
h(425+i) = uicontrol('Parent',h(200+i), ... % undistortion file name
'Units','characters','BackgroundColor',[0.83 0.82 0.78],...
'HorizontalAlignment','left',...
'Position',[51 0 40 2],'String','Undistortion file: none',...
'Style','text','Tag','text4','visible','on');
if i==1
set(h(325+i),'enable','off')
end
end
for i=1:uda.nvid
% browse for each video file
pause(0.01); % make sure that the uigetfile executed (MATLAB bug)
[fname1,pname1] = uigetfile( ...
{'*.avi;*.cin;*.cine;*.mp4;*.mrf;*.mov;*.MOV', ...
'All movie files (*.avi, *.cin, *.cine, *.mp4, *.mrf, *.mov)'; ...
'*.avi','AVI movies (*.avi)'; ...
'*.cin','Phantom movies (*.cin)'; ...
'*.cine','Phantom movies (*.cine)'; ...
'*.mp4','mpeg4 movies (*.mp4)'; ...
'*.mrf','IDT Redlake movies (*.mrf)'; ...
'*.mov','Apple movies (*.mov)'}, ...
sprintf('Pick movie file %.0d',i));
pause(0.01); % make sure that the uigetfile executed (MATLAB bug)
try
setappdata(h(300+i),'fname',[pname1,fname1]);
setappdata(h(300+i),'Userdata',uda);
setappdata(h(200+i),'Userdata',uda);
set(h(200+i),'Name',sprintf('Movie %.0f: %s',i,fname1));
% change directory
cd(pname1);
catch
disp('Initialization failed. Please try again.')
for j=1:i
set(h(200+j),'deletefcn','');
close(h(200+j));
end
return
end
end
% Initialize the data arrays
%
% set the slider size
movie1info=mediaInfo([pname1,fname1]);
if movie1info.NumFrames>1
set(h(5),'Max',movie1info.NumFrames,'Min',1,'Value',1,'SliderStep', ...
[1/(movie1info.NumFrames - 1) 1/(movie1info.NumFrames - 1)]);
else
set(h(5),'Max',2,'Min',1,'Value',1,'SliderStep',[1 1]);
end
% setup the DLTpts, DLTres & offsets arrays
uda.dltpts(1:movie1info.NumFrames,1:3)=NaN;
uda.dltres(1:movie1info.NumFrames,1)=NaN;
uda.offset(1:movie1info.NumFrames,1:uda.nvid)=0;
% setup the xypts array
uda.xypts(1:movie1info.NumFrames,1:2*uda.nvid)=NaN;
% setup the numpts (Number of Points) & currentpoint
uda.numpts=1; % number of points
uda.sp=1; % selected point
uda.recentlysaved=1; % has this data been saved
uda.reloadVid=false; % force reload of all videos
uda.predSeed.alpha=0.5; % double exponential predictor initial value
uda.gapJump=0; % number of "missing data" frames to try and skip over
uda.wdMode=false; % assume not in wing digitizing mode
currframe(i:uda.nvid,1)=1; % set current frame to 1 for all videos
cdataCache=cell(uda.nvid,1); % initialize cdataCache
% plot the first images in each axis
for i=1:uda.nvid
% make the axis of interest active and visible
set(h(i+300),'Visible','on');
% read the video frame; assume it is grayscale
movname=getappdata(h(i+300),'fname');
[mov,fname]=mediaRead(movname,1,false,false); % grab the 1st frame
setappdata(h(i+300),'fname',fname); % set the name (or mmreader obj)
% if we got an mmreader obj back, check for compression
if isstr(fname)==false
cstring=fname.VideoCompression;
k = strfind(lower(cstring),'-bit');
k2 = strfind(lower(cstring),'none');
if isempty(k) && isempty(k2)
disp(['Movie ',movname,' is compressed and may read slowly.'])
end
end
% store the movie frame sizes
uda.movsizes(i,1)=size(mov.cdata,1);
uda.movsizes(i,2)=size(mov.cdata,2);
% plot the frame
redlakeplot(mov.cdata(:,:),h(i+300));
colormap(h(i+300),gray(256));
cdataCache{i}=mov.cdata; % cache the image
set(gca,'XTickLabel','');
set(gca,'YTickLabel','');
setappdata(h(i+300),'Userdata',ud);
set(get(h(i+300),'Children'),'ButtonDownFcn','DLTdv5(3)');
setappdata(get(h(i+300),'Children'),'Userdata',ud);
% store an initial drawVid value
uda.drawVid(i)=true;
end
% query for calibrated cameras and load the DLT coefficients
if uda.nvid>1
dlt=questdlg('Are these cameras calibrated via DLT?','Use DLT?', ...
'yes','no','yes');
switch dlt % setup DLT coefficients of desired
case 'yes'
pause(0.01); % make sure that the uigetfile executed (MATLAB bug)
[fname1,pname1]=...
uigetfile({'*.csv;*.mat'},['Pick the DLT coefficients file or ',...
'combined data and coefficients *.MAT file']);
pause(0.01); % make sure that the uigetfile executed (MATLAB bug)
% if user loaded dltcoefs only
if strcmpi('.csv',fname1(end-3:end))
uda.dltcoef=dlmread([pname1,fname1],',');
uda.dltcoef=uda.dltcoef(:,1:uda.nvid); % prune to # of videos
% else if user loaded new matlab based data file
elseif strcmpi('.mat',fname1(end-3:end))
dltdata=[];
wd=[];
load([pname1,fname1]);
uda.dltcoef=dltdata.coefs(:,1:uda.nvid);
% if we also got wing position data
if exist('wd','var')
uda.wd=wd;
h=wingDataInit(h,ud,wd);
uda.wdMode=true;
end
end
uda.dlt=1; % DLT on
set(h(53),'enable','on')
set(h(61),'enable','on') % residual threshold
case 'no'
uda.dlt=0; % DLT off
end
else
uda.dlt=0; % DLT off (if uda.nvid~>1)
end
% create blank undistortion profile entries
uda.camd{i}=[];
uda.camud{i}=[];
% turn on the other controls
set(h(5),'enable','on'); % frame slider
set(h(7),'enable','on'); % save button
set(h(8),'enable','on'); % frame number text box
set(h(12),'enable','on'); % display color video checkbox
set(h(13),'enable','on'); % video gamma control
set(h(19),'enable','on'); % add point button
set(h(22),'enable','on'); % load previous data button
set(h(32),'enable','on'); % point # pulldown menu
set(h(35),'enable','on'); % autotrack pulldown menu
set(h(38),'enable','on'); % autotrack search area size textbox
set(h(39),'enable','on'); % autotrack threshold textbox
set(h(57),'enable','on'); % autotrack mode pull-down menu
% turn on Centroid finding & set value to "On" if the image analysis
% toolbox functions that it depends on are available
if exist('im2bw')~=0 && exist('regionprops')~=0 && ...
exist('bwlabel')~=0
set(h(55),'enable','on','Value',0);
disp('Detected Image Analysis toolbox, centroid localization is')
disp('available, enable it via the checkbox in the Controls window.')
else
disp('The Image Analysis toolbox is not available, centroid ')
disp('localization has been disabled.')
end
% if more than 1 video, enable to video updating checkbox
if uda.nvid >1
set(h(63),'enable','on');
end
% turn off the Initialize button
set(h(6),'enable','off');
% write the Userdata back
uda.handles=h; % copy in new handles
setappdata(h(1),'Userdata',uda);
setappdata(h(1),'currframe',currframe);
setappdata(h(1),'cdataCache',cdataCache);
% call self to update the string fields
DLTdv5(4,uda);
DLTdv5(1,uda);
%% case 1 - refresh video frames
case {1} % refresh the video frames
uda.drawVid;
currframe=getappdata(h(1),'currframe');
colorVal=get(h(12),'Value'); % get color mode info
% generate a new, gamma-scaled colormap if in grayscale mode
if colorVal==0 % gray
c=colormap(gray(256));
cnew=c.^get(h(13),'Value');
end
if strcmp(get(h(6),'enable'),'off')==1 % if initialized
fr=round(get(h(5),'Value')); % get the frame # from the slider
set(h(5),'Value',fr); % set the rounded value back
frmax=get(h(5),'Max'); % get the slider max
% loop through each axes and update it if appropriate
for i=1:uda.nvid
% check to see if we should update this axis
if uda.drawVid(i)==true || get(h(63),'Value')==true
fname=getappdata(h(i+300),'fname');
ud=getappdata(h(i+300),'Userdata');
xl=xlim(h(i+300));
yl=ylim(h(i+300));
% read the offset if not the first camera
offset=str2double(get(h(325+i),'String'));
% write the offset
uda.offset(fr,i)=offset;
% read the video frame if possible and/or necessary
if fr+offset <= 0 || fr+offset>frmax
% no image available
mov.cdata=chex(1,round(xl(2)),round(yl(2)));
cdataCache{i}=mov.cdata; % cache the image
elseif fr+offset ~= currframe(i) || uda.reloadVid==true
% need new image from file (or oData if autotracking)
try
if exist('oData','var')
mov=oData.movs{i};
if isempty(mov)
mov=mediaRead(fname,fr+offset,get(h(12),'Value'),...
get(h(350+i),'value'));
end
else
mov=mediaRead(fname,fr+offset,get(h(12),'Value'),...
get(h(350+i),'value'));
end
catch
mov.cdata=chex(1,round(xl(2)),round(yl(2)));
end
cdataCache{i}=mov.cdata; % cache the image
else
% image already in memory
cdataCache=getappdata(h(1),'cdataCache');
mov.cdata=cdataCache{i};
end
% plot the frame parameters
hold(h(300+i),'off')
if colorVal==0 %gray
redlakeplot(mov.cdata(:,:,1),h(i+300));
colormap(h(i+300),cnew);
elseif colorVal==1 && size(mov.cdata,3)==1 % color w/ gray video
redlakeplot(repmat(mov.cdata(:,:,1)+(1-get(h(13),'Value') ...
)*128,[1,1,3]),h(i+300));
else % color display with color video
% do the gamma scaling - since truecolor images don't have a
% colormap, it is not possible to do quick nonlinear transforms
% on the colormap instead of the image data itself. Therefore,
% we're forced to just do linear scaling - i.e. change the
% image brightness
cdata=mov.cdata+(1-get(h(13),'Value'))*128;
redlakeplot(cdata,h(i+300));
end
currframe(i)=fr+offset;
set((h(i+300)),'XTickLabel','');
set((h(i+300)),'YTickLabel','');
set(h(i+300),'ButtonDownFcn','DLTdv5(3)');
setappdata(get(h(i+300),'Children'),'Userdata',ud);
xlim(h(i+300),xl); ylim(h(i+300),yl); % restore axis zoom
hold(h(300+i),'on')
end
end % end for loop through the video axes
% call quickRedraw to add the non-image graphics
quickRedraw(uda,h,sp,fr);
% set the force redraw switch to false
uda.reloadVid=false;
% call self to update the text fields
DLTdv5(4,uda);
% write back any modifications to the main figure Userdata
setappdata(h(1),'Userdata',uda);
setappdata(h(1),'currframe',currframe);
setappdata(h(1),'cdataCache',cdataCache);
end
%% case 2 - key press callback
case {2} % handle keypresses in the figure window - zoom & unzoom axes
me = find(h==gcbo);
cc=get(h(me),'CurrentCharacter'); % the key pressed
pl=get(0,'PointerLocation'); % pointer location on the screen
pos=get(h(me),'Position'); % get the figure position
fr=round(get(h(5),'Value')); % get the current frame
% calculate pointer location in normalized units
plocal=[(pl(1)-pos(1,1)+1)/pos(1,3), (pl(2)-pos(1,2)+1)/pos(1,4)];
% if the keypress is empty or is a lower-case x, shut off the
% auto-tracker
if isempty(cc)
return
elseif cc=='x'
uda.drawVid(:)=true;
if get(h(35),'Value')<4
set(h(35),'Value',get(h(35),'Value')+1);
else
set(h(35),'Value',1);
end
setappdata(h(1),'Userdata',uda);
return
elseif cc=='X'
set(h(35),'Value',5);
return
else
if plocal(1)<=0.99 && plocal(2)<=0.99
axh=me+100; % axis handle for each figure is offset by +100
vnum=me-200; % video numbers are offset by -200
% store the axis handle and video number for use later
uda.lastaxh=axh;
uda.lastvnum=vnum;
else
%disp('The mouse pointer is not over a video.');
%return
try
axh=uda.lastaxh;
vnum=uda.lastvnum;
catch
estr=['The mouse pointer is not over a video & the last ', ...
'identity is uncertain.'];
disp(estr);
return
end
end
end
% process the key press
if (cc=='=' || cc=='-' || cc=='r') && axh~=0; % check for zoom keys
% zoom in or out as indicated
if axh~=0
axpos=get(h(axh),'Position'); % axis position in figure
xl=xlim; yl=ylim; % x & y limits on axis
% calculate the normalized position within the axis
plocal2=[(plocal(1)-axpos(1,1))/axpos(1,3) (plocal(2) ...
-axpos(1,2))/axpos(1,4)];
% check to make sure we're inside the figure!
if sum(plocal2>0.99 | plocal2<0)>0
disp('The pointer must be over a video during zoom operations.')
return
end
% calculate the actual pixel postion of the pointer
pixpos=round([(xl(2)-xl(1))*plocal2(1)+xl(1) ...
(yl(2)-yl(1))*plocal2(2)+yl(1)]);
% axis location in pixels (idealized)
axpix(3)=pos(3)*axpos(3);
axpix(4)=pos(4)*axpos(4);
% adjust pixels for distortion due to normalized axes
xRatio=(axpix(3)/axpix(4))/(diff(xl)/diff(yl));
yRatio=(axpix(4)/axpix(3))/(diff(yl)/diff(xl));
if xRatio > 1
xmp=xl(1)+(xl(2)-xl(1))/2;
xmpd=pixpos(1)-xmp;
pixpos(1)=pixpos(1)+xmpd*(xRatio-1);
elseif yRatio > 1
ymp=yl(1)+(yl(2)-yl(1))/2;
ympd=pixpos(2)-ymp;
pixpos(2)=pixpos(2)+ympd*(yRatio-1);
end
% set the figure xlimit and ylimit
if cc=='=' % zoom in
xlim([pixpos(1)-(xl(2)-xl(1))/3 pixpos(1)+(xl(2)-xl(1))/3]);
ylim([pixpos(2)-(yl(2)-yl(1))/3 pixpos(2)+(yl(2)-yl(1))/3]);
elseif cc=='-' % zoom out
xlim([pixpos(1)-(xl(2)-xl(1))/1.5 pixpos(1)+(xl(2)-xl(1))/1.5]);
ylim([pixpos(2)-(yl(2)-yl(1))/1.5 pixpos(2)+(yl(2)-yl(1))/1.5]);
else % restore zoom
xlim([0 uda.movsizes(vnum,2)]);
ylim([0 uda.movsizes(vnum,1)]);
end
% set drawnow for the axis in question
uda.drawVid(vnum)=true;
end
% check for valid movement keys
elseif cc=='f' || cc=='b' || cc=='F' || cc=='B' || cc=='<' || cc=='>' && axh~=0
fr=round(get(h(5),'Value')); % get current slider value
smax=get(h(5),'Max'); % max slider value
smin=get(h(5),'Min'); % max slider value
axn=axh-300; % axis number
if isnan(axn),
disp('Error: The mouse pointer is not in an axis.')
return
end
cp=uda.xypts(fr,axn*2-1:axn*2,sp); % set current point to xy value
if cc=='f' && fr+1 <= smax
if (get(h(35),'Value')==3 || get(h(35),'Value')==5) ...
&& isnan(cp(1))==0 % semi-auto tracking
keyadvance=1; % set keyadvance variable for DLTautotrack function
uda=DLTautotrack2fun(uda,h,keyadvance,axn,cp,fr,sp);
end
set(h(5),'Value',fr+1); % current frame + 1
fr=fr+1;
%%% WD mode stuff
% predict next frame (only works for 2 wings right now)
if uda.wdMode
if get(h(102),'Value')==1
wNum=1;
else
wNum=2;
end
if (isnan(sum(uda.wd.wingAngles(fr,:,wNum))) || ... % if NaN
sum(abs(uda.wd.wingAngles(fr,:,wNum)))==0) % or all zeros
if fr>36 % if enough points for a curve fit
samp=uda.wd.wingAngles(fr-36:fr-1,:,wNum);
if exist('tybutter','file')==2
samp=tybutter(samp,85,1000);
end
n(1,1)=doubleExpPredictor(samp(:,1));
n(2,1)=doubleExpPredictor(samp(:,2));
n(3,1)=doubleExpPredictor(samp(:,3));
uda.wd.wingAngles(fr,:,wNum)=n;
elseif fr>1
uda.wd.wingAngles(fr,:,wNum)=uda.wd.wingAngles(fr-1,:,wNum);
end
end
end
elseif cc=='b' && fr-1 >= smin
set(h(5),'Value',fr-1); % current frame - 1
fr=fr-1;
elseif cc=='F' && fr+50 < smax
set(h(5),'Value',fr+50); % current frame + 50
fr=fr+50;
elseif cc=='B' && fr-50 >= smin
set(h(5),'Value',fr-50); % current frame - 50
fr=fr-50;
elseif cc=='<' || cc=='>' % switch to start or end of this point in this camera
ptval=get(h(32),'Value'); % selected point
idx=find(isfinite(uda.xypts(:,vnum*2,ptval)));
if numel(idx)>0
if cc=='<'
set(h(5),'Value',idx(1));
else
set(h(5),'Value',idx(end));
end
end
end
% full redraw of the screen
DLTdv5(1,uda);
% update the control / zoom window
% 1st retrieve the cp from the data file in case the autotracker
% changed it
cp=uda.xypts(fr,vnum*2-1:vnum*2,sp);
updateSmallPlot(h,vnum,cp);
elseif cc=='n' % add a new point
yesNo=questdlg('Are you sure you want to add a point?',...
'Add a point?','Yes','No','No');
if strcmp(yesNo,'Yes')==1
DLTdv5(12,uda);
return
else
return
end
elseif cc=='.' || cc==',' % change point
% get current pull-down list (available points)
ptnum=numel(get(h(32),'String'))/3; % need str2num here
ptval=get(h(32),'Value'); % selected point
if cc==',' && ptval>1 % decrease point value if able
set(h(32),'Value',ptval-1);
ptval=ptval-1;
elseif cc=='.' && ptval<ptnum % increase pt value if able
set(h(32),'Value',ptval+1);
ptval=ptval+1;
end