-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatherCompiledFeatures.m
64 lines (52 loc) · 1.84 KB
/
gatherCompiledFeatures.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
function ftrs = gatherCompiledFeatures(outdir,expdir,stationary,varargin)
% function ftrs = gatherCompiledFeatures(outdir,expdir,stationary,varargin)
[moviename,trxfilename,method] = myparse(varargin,...
'moviename','movie.ufmf','trxfilename','trx.mat','method','deep-sup');
% [~,nframes] = get_readframe_fcn(fullfile(expdir,moviename));
[~,expname] = fileparts(expdir);
savename = fullfile(outdir,expname);
params = getParams;
allftrs = {};
tt = load(fullfile(expdir,trxfilename));
tracks = tt.trx;
ff = [tracks.firstframe];
ee = [tracks.endframe];
minfirst = min([tracks.firstframe]);
maxlast = max([tracks.endframe]);
nframes = maxlast-minfirst+1;
numblocks = ceil(nframes/params.blocksize);
for ndx = 1:numblocks
Q = load(sprintf('%s_%d.mat',savename,ndx));
allftrs{ndx} = Q.curftrs;
end
ff = fields(allftrs{1});
params = getParams;
mndx = find(strcmp(params.methods,method));
flowname = params.flownames{mndx};
% Initialize the struct for features of all the frames
ftrs = struct;
for fly = 1:numel(tracks)
frames_fly = tracks(fly).nframes;
for fnum = 1:numel(ff)
ftrsz = size(allftrs{1}.(ff{fnum}){1});
ftrsz(end) = [];
ftrs.(ff{fnum}){fly} = zeros([ftrsz frames_fly],'single');
end
end
% assign the features from each block.
for fnum = 1:numel(ff)
for flynum = 1:numel(tracks)
count = 1;
for bnum = 1:numel(allftrs)
numframes = size(allftrs{bnum}.(ff{fnum}){flynum});
numframes = numframes(end);
if numframes < 1, continue; end
% ftrs.(ff{fnum}){flynum}(:,count:count+numframes-1) = ...
% single(reshape(allftrs{bnum}.(ff{fnum}){flynum},[],numframes));
ftrs.(ff{fnum}){flynum}(:,:,:,count:count+numframes-1) = ...
single(allftrs{bnum}.(ff{fnum}){flynum});
count = count + numframes;
end
end
end
extractPerframeFtrs(fullfile(expdir,'perframe'),ftrs,stationary,flowname);