forked from cortex-lab/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweightsMeanImage.m
39 lines (34 loc) · 971 Bytes
/
weightsMeanImage.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
function [stat, we] = weightsMeanImage(ops, stat, m)
S = reshape(m.S, [], size(m.S, ndims(m.S)));
nBasis = size(S,2);
Nk = numel(stat);
Ireg = diag([ones(Nk,1); zeros(nBasis,1)]);
covL = [m.LtL m.LtS; m.LtS' m.StS] + 1e-2 * Ireg;
%%
mimg1 = ops.mimg1(ops.yrange, ops.xrange);
mimg1 = my_conv2(mimg1, ops.sig, [1 2]);
mimg1 = mimg1 - my_conv2(mimg1, 5*ops.diameter, [1 2]);
mimg1 = mimg1 ./ my_conv2(mimg1.^2, 5*ops.diameter, [1 2]).^.5;
% mimg1 = bsxfun(@rdivide, mimg1, m.sdmov);
mimg1 = mimg1(:);
Ftemp = zeros(Nk, 1, 'single');
for k = 1:Nk
ipix = stat(k).ipix(:)';
if ~isempty(ipix)
Ftemp(k) = stat(k).lam(:)' * mimg1(ipix);
end
end
%
if isempty(S)
we = covL \ Ftemp;
else
StU = S' * mimg1(:);
we = covL \ cat(1, Ftemp, StU);
end
we = we(1:Nk);
for j = 1:Nk
stat(j).mimgProj = we(j);
% take absolute value: some cells mean activity is below neuropil!
stat(j).mimgProjAbs = abs(we(j));
end
1;