-
Notifications
You must be signed in to change notification settings - Fork 2
/
real_WE_1fly.m
109 lines (94 loc) · 3.58 KB
/
real_WE_1fly.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
allfiles_ori = uigetfile('*crrcted.mat','MultiSelect','on');
if ~ischar(allfiles_ori)
allfiles = cell2struct(allfiles_ori,'name');
else
allfiles = struct;
allfiles(1).name = allfiles_ori;
end
vnum = 0;
for fi =1:length(allfiles)
load(allfiles(fi).name);
real_WE = zeros(size(WE));
vnum = vnum + 1;
disp( 'This is video No.');
disp(vnum);
% loop through fly 1 and 2
last_x = 0.0;
last_y = 0.0;
last_WE = 0;
for WE_i = 1:1
each_fly_WE = WE(WE_i,:);
sz = size(each_fly_WE);
sz = sz(2);
fprintf( 'This is fly No.%d\n', WE_i);
% disp(WE_i);
% initialize a 1-d array to save the real WE data
Counter = [];
% dist = [];
movie = VideoReader(moviefile);
i = 1;
while i <= sz
if each_fly_WE(i) == 1
count = 0;
walk = i;
while walk < sz && each_fly_WE(walk) == 1
count = count + 1;
walk = walk + 1;
end
Counter = [Counter, count];
if count >5
disp(pdist([posx(WE_i, i), posy(WE_i, i);last_x,last_y]));
if pdist([posx(WE_i, i), posy(WE_i, i);last_x,last_y]) < 50
real_WE(WE_i, i:walk-1) = last_WE;
i = walk + 1;
continue;
end
for fm = i:i+3
ff = read(movie,fm);
ff_label = insertText(ff,[posx(WE_i, fm)-10, posy(WE_i, fm)-10],'here');
imshow(ff_label);
end
% prompt = 'Do you want to stop? Y/N [Y]: ';
% if_stop = input(prompt,'s');
% if isempty(if_stop) || if_stop == 'Y' || if_stop == 'y'
% break;
% end
% end
while 1
prompt = 'Real / Not Real / Rewatch (Y/N/R) [Y]: ';
if_real = input(prompt,'s');
if strcmp(if_real,'Y') | strcmp(if_real,'Y') | strcmp(if_real,'')
real_WE(WE_i, i:walk-1) = 1;
last_WE = 1;
last_x = posx(WE_i, i);
last_y = posy(WE_i, i);
break;
elseif(if_real == 'R') | (if_real == 'r')
for fm = i:i+3
ff = read(movie,fm);
ff_label = insertText(ff,[posx(WE_i, fm)-10, posy(WE_i, fm)-10],'here');
imshow(ff_label);
end
else
disp('Not real WE, posx,y recorded');
last_WE = 0;
last_x = posx(WE_i, i);
last_y = posy(WE_i, i);
break;
end
end
disp( [ 'You just watched frame No.' num2str( i )]);
disp(' ');
end
i = walk + 1;
else
i = i + 1;
end
end
end
save(allfiles(fi).name,'real_WE','-append')
clearvars -except allfiles fi vnum;
end
% disp(mean(dist))
% disp(counter);
% hist(Counter,unique(Counter));