-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualizeFlowFeaturesSeq.m
151 lines (126 loc) · 3.28 KB
/
VisualizeFlowFeaturesSeq.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
function im = VisualizeFlowFeaturesSeq(bdir,fly,fnum,method)
%% inputs.
method = 'hs-sup';
if strcmp(method,'LK')
fname = 'ff';
elseif strcmp(method,'hs-brightness')
fname = 'hs_ff';
elseif strcmp(method,'hs-sup')
fname = 'hs_sup';
else
error('Unknown method %s',method);
end
fname = [fname 's'];
moviename = fullfile(bdir,'movie.ufmf');
trackfilename = fullfile(bdir,'trx.mat');
%% params
params = getParams;
npatches = params.npatches;
psize = params.psize;
nbins = params.nbins;
patchsz = params.patchsz;
scale = params.scale;
% this seems to be what the centers correspond to
bincenters = linspace(0,pi,nbins+1);
bincenters = bincenters(1:nbins);
% mayank divides by 2
bincenters2 = bincenters*2;
dt = mean(diff(bincenters2));
binedges2 = [bincenters2(1)-dt/2,(bincenters2(1:end-1)+bincenters2(2:end))/2,bincenters2(end)+dt/2];
%% Sequence
seqlen = 4;
nshow = 10;
fstart = fnum-seqlen;
fend = fnum+seqlen;
%%
tracks = load(trackfilename);
tracks = tracks.trx;
[readfcn,nframes,fid,headerinfo] = get_readframe_fcn(moviename);
im1 = [];im2 = [];
count = 1;
for fno = fstart:fend+1
i1 = readfcn(fno);
trackndx = fno - tracks(fly).firstframe + 1;
locy = round(tracks(fly).y(trackndx));
locx = round(tracks(fly).x(trackndx));
im1(:,:,count) = extractPatch(i1,...
locy,locx,tracks(fly).theta(trackndx),patchsz);
count = count+1;
end
F = zeros(npatches,npatches,nbins,2*seqlen+1);
parfor yy = 1:npatches
for xx = 1:npatches
for oo = 1:nbins
pfname = fullfile(bdir,'perframe',sprintf('%s_%02d_%02d_%d.mat',fname,yy,xx,oo));
q = load(pfname);
trackndx = fnum - tracks(fly).firstframe + 1;
F(yy,xx,oo,:) = q.data{fly}(trackndx-seqlen:trackndx+seqlen);
end
end
end
Fall = F;
F = mean(Fall,4);
%% plot
icol = hsv(nshow);
idx = round(linspace(1,2*seqlen+2,nshow));
cimg = zeros(size(im1,1),size(im1,2),3);
count = 1;
for ndx = idx(:)'
for ch = 1:3
cimg(:,:,ch) = cimg(:,:,ch)+im1(:,:,ndx)*icol(count,ch);
end
count = count+1;
end
for ch = 1:3
cimg(:,:,ch)= cimg(:,:,ch)/sum(icol(:,ch));
end
cimg = min(im1,[],3);
% cimg = zeros(size(im1,1),size(im1,2),3);
% tim1 = im1(:,:,idx);
% [mimg,mndx] = min(tim1,[],3);
% for ndx = 1:numel(idx)
% for ch=1:3
% jj = cimg(:,:,ch);
% kk = tim1(:,:,ndx);
% selpx = abs(kk-mimg)<65;
% jj(selpx)= jj(selpx) + kk(selpx)*icol(ndx,ch);
% cimg(:,:,ch) = jj;
% end
% end
% for ch = 1:3
% cimg(:,:,ch)= cimg(:,:,ch)/sum(icol(:,ch));
% end
hfig = figure;
clf;
hax = axes('Position',[0,0,1,1]);
set(hfig,'Units','pixels','Position',get(0,'ScreenSize'));
him = imshow(uint8(imresize(cimg,scale)));
axis image;
truesize;
hold on;
axis off;
%%
colors = hsv(nbins);
[nr,nc,~] = size(im1);
% maxv2 = max(F(:));
maxv2 = 1;
h = [];
for xi = 1:ceil(nc/psize),
cx = (psize/2 + (xi-1)*psize)*scale1 +1;
if cx+psize/2 > nc*scale,
break;
end
for yi = 1:ceil(nr/psize),
cy = (psize/2 + (yi-1)*psize)*scale+1;
if cy+psize/2 > nr*scale,
break;
end
for bini = 1:nbins,
tmp = linspace(binedges2(bini),binedges2(bini+1),20);
xcurr = cx + [0,psize/2*cos(tmp),0]*scale;
ycurr = cy + [0,psize/2*sin(tmp),0]*scale;
h(yi,xi,bini) = patch(xcurr,ycurr,colors(bini,:),'LineStyle','none','FaceAlpha',min(1,F(yi,xi,bini)/maxv2));
end
end
end
im = getframe(hax);