Skip to content

Commit 1e050c1

Browse files
committed
cleaning up
1 parent 412062d commit 1e050c1

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

run_CNMF_patches.m

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@
150150
else
151151
Atemp(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) = reshape(RESULTS(i).A(:,k),patches{i}(2)-patches{i}(1)+1,patches{i}(4)-patches{i}(3)+1,patches{i}(6)-patches{i}(5)+1);
152152
end
153-
%A(:,(i-1)*K+k) = sparse(Atemp(:));
154153
A(:,cnt) = sparse(Atemp(:));
155154
end
156155
end
@@ -164,6 +163,9 @@
164163
IND(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4)) = IND(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4)) + 1;
165164
P.psdx(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),:) = reshape(RESULTS(i).P.psdx,patches{i}(2)-patches{i}(1)+1,patches{i}(4)-patches{i}(3)+1,[]);
166165
else
166+
b_temp = sparse(sizY(1),sizY(2),sizY(3));
167+
b_temp(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) = reshape(RESULTS(i).b,patches{i}(2)-patches{i}(1)+1,patches{i}(4)-patches{i}(3)+1,patches{i}(6)-patches{i}(5)+1);
168+
MASK(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) = MASK(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) + 1;
167169
P.sn(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) = reshape(RESULTS(i).P.sn,patches{i}(2)-patches{i}(1)+1,patches{i}(4)-patches{i}(3)+1,patches{i}(6)-patches{i}(5)+1);
168170
P.active_pixels(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) = P.active_pixels(patches{i}(1):patches{i}(2),patches{i}(3):patches{i}(4),patches{i}(5):patches{i}(6)) + ...
169171
reshape(RESULTS(i).P.active_pixels,patches{i}(2)-patches{i}(1)+1,patches{i}(4)-patches{i}(3)+1,patches{i}(6)-patches{i}(5)+1);
@@ -217,43 +219,19 @@
217219
end
218220
fprintf(' done. \n');
219221
%% classify components
220-
% ff = classify_components(Am,Pm,options);
221-
% A = Am(:,ff);
222-
% C = Cm(ff,:);
223-
A = Am;
224-
C = Cm;
222+
ff = classify_components(Am,Pm,options);
223+
A = Am(:,ff);
224+
C = Cm(ff,:);
225225

226-
%% update spatial components
227-
fprintf('Updating spatial components...');
228-
% FIRST COMPUTE A TEMPORAL BACKGROUND
229-
% fin = zeros(1,T);
230-
% %empty_pixels = (sum(Am,2)==0);
231-
% empty_pixels = (~P.active_pixels);
232-
% q = diff([0,empty_pixels]);
233-
% fp = find(q==1);
234-
% fm = [find(q==-1)-1,T];
235-
% cnt = 0;
236-
% for i = 1:length(fp)
237-
% fin = cnt*fin/(cnt+fm(i)-fp(i)+1) + (fm(i)-fp(i)+1)*mean(double(squeeze(data.Yr(fp(i):fm(i),:))),1)/(cnt+fm(i)-fp(i)+1);
238-
% cnt = cnt + fm(i)-fp(i)+1;
239-
% end
240-
241-
% bsum = zeros(length(patches),1);
242-
% for i = 1:length(patches)
243-
% bsum(i) = sum(RESULTS(i).b);
244-
% end
245-
% bsum = bsum/sum(bsum);
246-
% f_p = cell2mat({RESULTS(:).f}');
247-
% fin = mean(spdiags(bsum,0,length(patches),length(patches))*f_p);
248-
% fin = medfilt1(fin,11);
226+
%% compute spatial and temporal background using a rank-1 fit
249227

250228
fin = mean(F);
251229
for iter = 1:10
252230
bin = max(B*(F*fin')/norm(fin)^2,0);
253231
fin = max((bin'*B)*F/norm(bin)^2,0);
254232
end
255-
%%
256-
% PROCESS PATCHES
233+
%% update spatial components
234+
fprintf('Updating spatial components...');
257235
options.d1 = sizY(1);
258236
options.d2 = sizY(2);
259237
if length(sizY) == 4; options.d3 = sizY(3); end

update_temporal_components.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@
147147
AA = (A'*A)/spdiags(nA(:),0,length(nA),length(nA));
148148
if memmaped
149149
YA = zeros(T,length(nA));
150-
tic;
151150
for i = 1:step:d
152151
YA = YA + double(Y.Yr(i:min(i+step-1,d),:))'*A(i:min(i+step-1,d),:);
153152
end
154-
toc
155153
YA = YA/spdiags(nA(:),0,length(nA),length(nA));
156154
else
157155
YA = (Y'*A)/spdiags(nA(:),0,length(nA),length(nA));

0 commit comments

Comments
 (0)