forked from llerussell/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_registration.m
More file actions
47 lines (43 loc) · 1.45 KB
/
Copy pathtest_registration.m
File metadata and controls
47 lines (43 loc) · 1.45 KB
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
47
function err = test_registration(frame, nTrans, useGPU)
%test_registration Test registration by registering a randomly shifted frame
% Shifts a frame with nTrans random translations then registers adds
% nosie to each frame and attempts to register them back to the frame.
% Returns the mean square error of the registration offsets with the
% original translations
if nargin < 2
nTrans = 1000;
end
if nargin < 3
useGPU = false;
end
frame = single(frame);
dvrSigma = 2;
noiseSigma = std(frame(:))/3;
dvr = [0 0; dvrSigma*randn(nTrans - 1, 2)];
ops = struct('useGPU', useGPU, 'PhaseCorrelation', true, 'mimg', [],...
'SubPixel', inf, 'registrationUpsample', 1, 'regPrecision', 'same');
movie = repmat(frame, [1 1 nTrans]);
[transFrame, validIdx] = translate_movie(movie, dvr, ops);
transFrame = transFrame(validIdx{1},validIdx{2},:);
transFrame = transFrame + noiseSigma*randn(size(transFrame), 'single');
ops.mimg = transFrame(:,:,1);
%%
tic
nreps = 1;
for i = 1:nreps
reg_new = registration_offsets(transFrame, ops, false);
end
dt_new = toc;
tic
for i = 1:nreps
reg_old = registration_offsets_old(transFrame, ops, false);
end
dt_old = toc;
err_old = mean((dvr(:) - reg_old(:)).^2);
err_new = mean((dvr(:) - reg_new(:)).^2);
oldTimesMoreError = (err_old)/(err_new);
fprintf('dt_new=%.2fs, dt_old=%.2fs old gave %.1f times more MSE\n',dt_new,dt_old,oldTimesMoreError);
err = err_new;
% ff = 1:nTrans;
% plot(ff, dvr(:,1)-crv(:,1),'b',ff, dvr(:,2)-crv(:,2),'r');
end