|
150 | 150 | else |
151 | 151 | 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); |
152 | 152 | end |
153 | | - %A(:,(i-1)*K+k) = sparse(Atemp(:)); |
154 | 153 | A(:,cnt) = sparse(Atemp(:)); |
155 | 154 | end |
156 | 155 | end |
|
164 | 163 | 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; |
165 | 164 | 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,[]); |
166 | 165 | 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; |
167 | 169 | 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); |
168 | 170 | 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)) + ... |
169 | 171 | 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 | 219 | end |
218 | 220 | fprintf(' done. \n'); |
219 | 221 | %% 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,:); |
225 | 225 |
|
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 |
249 | 227 |
|
250 | 228 | fin = mean(F); |
251 | 229 | for iter = 1:10 |
252 | 230 | bin = max(B*(F*fin')/norm(fin)^2,0); |
253 | 231 | fin = max((bin'*B)*F/norm(bin)^2,0); |
254 | 232 | end |
255 | | -%% |
256 | | -% PROCESS PATCHES |
| 233 | +%% update spatial components |
| 234 | +fprintf('Updating spatial components...'); |
257 | 235 | options.d1 = sizY(1); |
258 | 236 | options.d2 = sizY(2); |
259 | 237 | if length(sizY) == 4; options.d3 = sizY(3); end |
|
0 commit comments