forked from cortex-lab/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign_iterative.m
37 lines (28 loc) · 908 Bytes
/
align_iterative.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
function ops = align_iterative(data, ops)
% uu = squeeze(sum(sum(data(:,:,:).^2,1),2));
% [~, isort] = sort(uu, 'descend');
% ops.mimg = data(:,:,isort(50));
ops.mimg = pick_reg_init(data);
dsold = zeros(size(data,3), 2);
err = zeros(ops.NiterPrealign, 1);
%%
tempSubPixel = ops.SubPixel;
ops.SubPixel = Inf;
for i = 1:ops.NiterPrealign
[dsnew, Corr] = registration_offsets(data, ops, 1);
dreg = register_movie(data, ops, dsnew);
[~, igood] = sort(Corr, 'descend');
if i<floor(ops.NiterPrealign/2)
igood = igood(1:100);
else
igood = igood(1:round(size(data,3)/2));
end
ops.mimg = mean(dreg(:,:,igood),3);
err(i) = mean(sum((dsold - dsnew).^2,2)).^.5;
dsold = dsnew;
end
ops.SubPixel = tempSubPixel;
ops.AlignNanThresh = median(Corr) - 4*std(Corr);
ops.ErrorInitialAlign = err;
ops.dsprealign = dsnew;
end