-
Notifications
You must be signed in to change notification settings - Fork 5
/
texturesinregions.m
176 lines (119 loc) · 3.43 KB
/
texturesinregions.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
LOAD = 1
COMPUTE =1
PLOT =0
TEST = 0;
path = '/data/videos/onlinelearning/new';
VIDID = 2;
if LOAD && ~exist('ft','var')
opts = [];
opts.nfish = 3;
videoFile = [path filesep mfilename sprintf('F%d-%d.avi',opts.nfish,VIDID)];
opts.detector.inverted = 1;
opts.stmif = 1;
opts.display.videoHandler = true;
opts.stimulus.screen = 1;
opts.stimulus.presenter = 'fish.stimulus.PresenterTrackTextureRegions';
opts.detector.adjustThresScale = 1.05;
opts.fishwidth = 35;
opts.fishlength = 150;
opts.detector.history = 5000;
ft = fish.Tracker({0,videoFile},opts);
end
if COMPUTE
if ~exist('sbbox','var')
%sbbox = fish.Tracker.calibrateStimulusScreen(0,1);
%sbbox = [115,90,1550,1214];
sbbox = [147,71,1555,1237];
end
opts = [];
opts.avgVelocity = 5;
opts.maxVelocity = 30;
opts.display.displayEveryNFrame = 100;
ostm = [];
ostm.screenBoundingBox = sbbox;
ostm.usePredFishId = false;
ostm.stmCol= parula(ft.nfish);
ostm.stmOnInt= 2; % in sec
ostm.stmOnIntCV= 0.1;
ostm.stmOffInt= 4; % in sec
ostm.stmOffIntCV= 0.5;
ostm.stmSize = ft.fishlength;
ostm.regSizeFactorScale = [0,1,2];
ostm.stmSizeFactor = 1;
ostm.xRegions = [1/3,2/3];
ostm.stmShift = ft.fishlength/4; % in px of fish.tracker frame
ostm.stmShiftOri = 0;
ostm.stmShiftOriSTD = -1; % random;
ostm.stmShiftCV = 2;
ostm.stmSizeFactorCV = 0.25;
ostm.stmVelThres = [2];
ostm.stmBorderThres = 0.05;
ostm.funLRStm = @(fishIds) fishIds;
ostm.colBackground = [0,0,0];
ostm.colBorder = [1,1,1];
ostm.borderWidth = 0.00;
ostm.adaptationTime = 30;
ostm.tmax = 3600*2;
opts.stimulus = ostm;
ft.setOpts(opts);
%ft.setDisplay(0);
ft.setDisplay('tracks',false);
if TEST
fish.helper.stimulusSimulator(ft.stimulusPresenter);
else
ft.track();
ft.save();
end
clear ft;
end
if PLOT
dagresults = 1;
ft.setDefaultResultType(dagresults);
res = ft.getTrackingResults();
pos = ft.interpolateInvisible(res,'pos');
info = res.tracks.stmInfo;
stmmsk = info(:,1,1)==ft.stimulusPresenter.ID_STIMULUS;
som = nanmean(pos,3);
ssom = nanstd(sqrt(sum(bsxfun(@minus,pos,som).^2,2)),[],3);
return
pos = res.pos;
velocity = ft.deleteInvisible(res,'velocity');
vel = sqrt(velocity(:,:,1).^2+velocity(:,:,2).^2);
mpos1 = squeeze(nanmean(pos(stmmsk,:,:),1));
mpos2 = squeeze(nanmean(pos(nonmsk,:,:),1));
mvel1 = nanmean(vel(stmmsk,:),1);
mvel2 = nanmean(vel(nonmsk,:),1);
svel1 = fish.helper.stderr(vel(stmmsk,:),1);
svel2 = fish.helper.stderr(vel(nonmsk,:),1);
figure;
subplot(2,1,1);
plot(res.tabs,squeeze(pos(:,1,:)));
title('x')
hold on;
plot(res.tabs,stmmsk*100-100,'linewidth',2);
subplot(2,1,2);
plot(res.tabs,squeeze(pos(:,2,:)));
title('y')
hold on;
plot(res.tabs,stmmsk*100-100,'linewidth',2);
figure;
a = subplot(2,1,1);
vel = ft.deleteInvisible(res,'velocity');
vabs = sqrt(vel(:,:,1).^2 + vel(:,:,2).^2);
vabs(vabs>100) = NaN;
acc = [diff(vabs);zeros(1,size(vabs,2))];
%maxacc = 20;
%vabs(abs(acc)>maxacc) = NaN;
plot(res.tabs,vabs);
ylabel('Velocity [px/s]');
xlabel('Time [s]');
hold on;
plot(res.tabs,stmmsk*10-10,'linewidth',2);
b = subplot(2,1,2);
plot(res.tabs(1:end-1),conv2(diff(vabs),ones(5,1)/5,'same'));
ylabel('Accelleration [px/s^2]');
xlabel('Time [s]');
hold on;
plot(res.tabs,stmmsk*1-1,'linewidth',2);
linkaxes([a,b],'x')
end