forked from cortex-lab/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redoRegistration.asv
46 lines (40 loc) · 1.33 KB
/
redoRegistration.asv
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
function redoRegistration(ops)
if isfield(ops, 'gchannel') && ~isempty(ops.gchannel); ichannel = ops.gchannel;
else ichannel = 1; end
fs = ops.fsroot;
nchannels = ops.nchannels;
regdir = fileparts(ops.RegFile);
if ~exist(regdir, 'dir')
mkdir(regdir);
end
% open bin file for writing
fid = fopen(ops.RegFile, 'w');
iplane0 = ops.iplane;
dsall = ops.DS;
for k = 1:length(fs)
ds = dsall(sum(ops.Nframes((1:length(fs))<k)) + 1:ops.Nframes(k),:);
ds = ds(iplane0:ops.nplanes:end,:);
frCount = 0;
for j = 1:length(fs{k})
nFr = img.nFrames(fs{k}(j).name);
framePlanes =
firstFrame = find(mod(frCount+(1:nchannels*ops.nplanes), ...
nchannels*ops.nplanes) == nchannels*(iplane0-1)+ichannel);
ichanset = [firstFrame; nFr; nchannels*ops.nplanes];
data = loadFramesBuff(fs{k}(j).name, ichanset(1), ichanset(2), ...
ichanset(3));
ix0 = 0;
Nbatch = 1000;
dreg = zeros(size(data), class(data));
while ix0<size(data,3)
indxr = ix0 + (1:Nbatch);
indxr(indxr>size(data,3)) = [];
dreg(:, :, indxr) = ...
register_movie(data(:, :, indxr), ops, ds(indxr,:));
ix0 = ix0 + Nbatch;
end
fwrite(fid, dreg, class(data));
frCount = frCount + nFr;
end
end
fclose(fid);