-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_correction.m
342 lines (242 loc) · 10.4 KB
/
check_correction.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
%MANUAL_CORRECTION Summary of this function goes here
% Detailed explanation goes here
function [] = check_correction()
allfiles_ori = uigetfile('*.mp4','MultiSelect','on');
if ~ischar(allfiles_ori)
allfiles = cell2struct(allfiles_ori,'name');
else
allfiles = struct;
allfiles(1).name = allfiles_ori;
end
mi = 1;
L = load(strcat(allfiles(mi).name(1:end-4),'_crrcted','.','mat'));
moviefile = L.moviefile;
movie = VideoReader(moviefile);
nframes = get(movie,'NumberOfFrames');
startframe = L.StartTracking;
frame = startframe;
moviefigure =[];
f1 = [];
framecontrol = [];
framecontrol2 = [];
switchbutton=[];
cop_button = [];
nextfilebutton=[];
skipthisbutton=[];
th=[];
jump2start = [];
jump2stop = [];
fwd200 = [];
bckwd200 = [];
CreateGUI;
showimage;
function [] = CreateGUI(eo,ed)
titletext = allfiles(mi).name;
moviefigure = figure('Position',[150 250 900 600],'Name',titletext,'Toolbar','none','Menubar','none','NumberTitle','off','Resize','off','HandleVisibility','on','KeyPressFcn', @keyPress);
f1 = figure('Position',[150 70 900 100],'Toolbar','none','Menubar','none','NumberTitle','off','Resize','on','HandleVisibility','on','KeyPressFcn', @keyPress);
framecontrol = uicontrol(f1,'Position',[53 45 550 20],'Style','slider','Value',startframe,'Min',7,'Max',nframes,'SliderStep',[1/nframes 10/nframes],'Callback',@framecallback);
th(1)=uicontrol(f1,'Position',[1 45 50 20],'Style','text','String','frame #');
framecontrol2 = uicontrol(f1,'Position',[383 5 60 20],'Style','edit','String',mat2str(frame),'Callback',@frame2callback);
th(2)=uicontrol(f1,'Position',[320 5 60 20],'Style','text','String','frame #');
switchbutton = uicontrol(f1,'Position',[750 40 120 30],'Style','pushbutton','String','Switch 1&2','Callback',@swithch_fly_callback);
cop_button = uicontrol(f1,'Position',[750 10 120 30],'Style','pushbutton','String','Mark Cop','Callback',@cop_callback);
nextfilebutton = uicontrol(f1,'Position',[223 5 50 30],'Style','pushbutton','String','Next File','Enable','on','Callback',@nextcallback);
skipthisbutton = uicontrol(f1,'Position',[123 5 50 30],'Style','pushbutton','String','Skip This','Enable','on','Callback',@cannotanalysecallback);
jump2start = uicontrol(f1,'Position',[450 5 80 30],'Style','pushbutton','String','Jump to Start','Enable','on','Callback',@jump2start_callback);
jump2stop = uicontrol(f1,'Position',[550 5 80 30],'Style','pushbutton','String','Jump to Stop','Enable','on','Callback',@jump2stop_callback);
fwd200 = uicontrol(f1,'Position',[630 40 80 30],'Style','pushbutton','String','--> 200','Enable','on','Callback',@fwd200_callback);
bckwd200 = uicontrol(f1,'Position',[630 10 80 30],'Style','pushbutton','String','<-- 200','Enable','on','Callback',@bckwd200_callback);
end
function [] = nextcallback(eo,ed)
disp('next call back running')
% L.is_manual_corrected = 1;
savetrackdata;
if mi == length(allfiles)
delete(moviefigure)
delete(f1)
else
% clear all old variables
disp('OK. Next file.')
disp(allfiles(mi).name),disp('finished')
% delete all GUI elements
delete(framecontrol)
delete(framecontrol2)
delete(switchbutton)
delete(nextfilebutton)
delete(skipthisbutton)
delete(th(1))
delete(th(2))
delete(cop_button)
delete(moviefigure)
delete(f1)
delete(jump2start)
delete(jump2stop)
delete(fwd200)
delete(bckwd200)
% redraw entire GUI
clearvars -except allfiles mi;
mi = mi+1;
movie = VideoReader(allfiles(mi).name);
nframes = get(movie,'NumberOfFrames');
L = load(strcat(allfiles(mi).name(1:end-4),'_crrcted','.','mat'));
startframe = L.StartTracking;
frame = startframe; % current frame
% delete(framecontrol)
% framecontrol = uicontrol(f1,'Position',[53 45 600 20],'Style','slider','Value',startframe,'Min',7,'Max',nframes,'SliderStep',[1/nframes 10/nframes],'Callback',@framecallback);
CreateGUI;
% update GUI
titletext = allfiles(mi).name;
set(moviefigure,'Name',titletext);
set(framecontrol,'Value',startframe);
framecallback
showimage;
disp(allfiles(mi).name),disp('started')
end
end
function keyPress(eo,ed)
switch ed.Key
case 'c'
fwd200_callback(fwd200, []);
case 'x'
bckwd200_callback(bckwd200,[]);
end
end
function [] = cannotanalysecallback(eo,ed)
% move this to cannot-analyse
if exist('cannot-manual-corrected','dir') == 0 %7 in exist() return means directory
% make it when no 'cannot-analyse' folder
mkdir('cannot-manual-corrected')
end
% move the movie and mat data to a subfolder cannot-manual-corrected
thisfile = allfiles(mi).name;
movefile(thisfile,strcat('cannot-manual-corrected',oss,thisfile))
movefile(strcat(thisfile(1:end-4),'_anno','.mat'),strcat('cannot-manual-corrected',oss,strcat(thisfile(1:end-4),'_anno','.mat')))
try
movefile(strcat(thisfile(1:end-4),'_crrcted','.mat'),strcat('cannot-manual-corrected',oss,strcat(thisfile(1:end-4),'_crrcted','.mat')))
catch
disp('Correction file has not been generated. Do not need to move.')
end
nextcallback;
end
function [] = framecallback(eo,ed)
frame = ceil((get(framecontrol,'Value')));
showimage();
set(framecontrol2,'String',mat2str(frame));
end
function [] = frame2callback(eo,ed)
frame = ceil(str2double(get(framecontrol2,'String')));
showimage();
set(framecontrol,'Value',(frame));
end
function [] = fwd200_callback(eo,ed)
frame = frame +200;
set(framecontrol,'Value',(frame));
framecallback;
showimage();
end
function [] = bckwd200_callback(eo,ed)
frame = frame -200;
set(framecontrol,'Value',(frame));
framecallback;
showimage();
end
function [] = swithch_fly_callback(eo,ed)
frame = ceil(str2double(get(framecontrol2,'String')));
%keyboard;
% disp(L.posx(1,frame))
% disp(L.posx(2,frame))
%
L.posx = switch_1_2(L.posx);
% disp(L.posx(1,frame))
% disp(L.posx(2,frame))
L.posy = switch_1_2(L.posy);
L.WE = switch_1_2(L.WE);
L.orientation = switch_1_2(L.orientation);
L.MajorAxis = switch_1_2(L.MajorAxis);
L.MinorAxis = switch_1_2(L.MinorAxis);
L.area = switch_1_2(L.area);
savetrackdata;
L = load(strcat(allfiles(mi).name(1:end-4),'_crrcted','.mat'));
showimage();
%keyboard;
end
function [] = cop_callback(eo,ed)
for fm = frame:L.StopTracking
if ~isnan(L.posx(1,fm))
L.posx(2,fm) = L.posx(1,fm);
else
L.posx(1,fm) = L.posx(2,fm);
end
if ~isnan(L.posy(1,fm))
L.posy(2,fm) = L.posy(1,fm);
else
L.posy(1,fm) = L.posy(2,fm);
end
L.WE(1,fm) = NaN;
L.WE(2,fm) = NaN;
L.collisions(fm) = 1;
L.fly_apart_error_s(fm) = 99;
end
showimage();
savetrackdata;
end
function [] = jump2start_callback(eo,ed)
set(framecontrol,'Value',L.StartTracking)
framecallback
end
function [] = jump2stop_callback(eo,ed)
set(framecontrol,'Value',L.StopTracking)
framecallback
end
function [] = showimage(eo,ed)
ff = read(movie,frame);
fly_1_x = max(0,L.posx(1,frame));
fly_2_x = max(0,L.posx(2,frame));
fly_1_y = max(0,L.posy(1,frame));
fly_2_y = max(0,L.posy(2,frame));
fly_ID_insert = vision.TextInserter('%s', 'LocationSource', 'Input port', 'Color', [255, 0, 0], 'FontSize', 24);
strings_fly_ID = uint8(['M' 0 'F']);
ff = step(fly_ID_insert, ff, strings_fly_ID, int32([fly_1_x fly_1_y;fly_2_x fly_2_y]));
if frame > L.StopTracking
fly_stop_insert = vision.TextInserter('%s', 'LocationSource', 'Input port', 'Color', [255, 0, 0], 'FontSize', 50);
strings_stop = uint8('Tracking Stopped');
ff = step(fly_stop_insert, ff, strings_stop, int32([80,240]));
end
figure(moviefigure), axis image
imagesc(ff);
title(frame);
end
function [] = savetrackdata(eo,ed)
filename = allfiles(mi).name;
posx = L.posx;
posy = L.posy;
WE = L.WE;
orientation = L.orientation;
MajorAxis = L.MajorAxis;
MinorAxis = L.MinorAxis;
area = L.area;
moviefile = allfiles(mi).name;
% is_manual_corrected = L.is_manual_corrected;
fly_apart_error_s = L.fly_apart_error_s;
collisions = L.collisions;
ROIs = L.ROIs;
StartTracking = L.StartTracking;
StopTracking = L.StopTracking;
thresh_ROIs = L.thresh_ROIs;
Channel = L.Channel;
min_body_dist_s = L.min_body_dist_s;
save(strcat(filename(1:end-4),'_crrcted','.mat'),'posx','posy','WE',...
'orientation','MajorAxis','MinorAxis','area','moviefile',...
'fly_apart_error_s','collisions','ROIs','StartTracking',...
'StopTracking','thresh_ROIs','Channel','min_body_dist_s');
disp('saved');
end
function M_2_by_n = switch_1_2(M_2_by_n)
for fm = frame:L.StopTracking
temp = M_2_by_n(1,fm);
M_2_by_n(1,fm) = M_2_by_n(2,fm);
M_2_by_n(2,fm) = temp;
end
disp('Swith done')
end
end