-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjksbxalignx.m
53 lines (39 loc) · 1.16 KB
/
jksbxalignx.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [m,T] = jksbxalignx(fname,idx, varargin)
% Aligns images in fname for all indices in idx
%
% m - mean image after the alignment
% T - optimal translation for each frame
%
if nargin < 3
ch = 1; % green (pmt0) when 2 channel imaging.
else
ch = varargin{1}; % 1 for green (pmt0), 2 for red (pmt1) when 2 channel imaging
end
if(length(idx)==1)
A = sbxread(fname,idx(1),1);
A = squeeze(A(ch,:,:));
m = A;
T = [0 0];
elseif (length(idx)==2)
A = sbxread(fname,idx(1),1);
B = sbxread(fname,idx(2),1);
A = squeeze(A(ch,:,:));
B = squeeze(B(ch,:,:));
Ap = A(151:end-50,151:end-50);
Bp = B(151:end-50,151:end-50);
[u, v] = fftalign(Ap,Bp);
Ar = circshift(A,[u,v]);
m = (Ar+B)/2;
T = [[u v] ; [0 0]];
else
idx0 = idx(1:floor(end/2));
idx1 = idx(floor(end/2)+1 : end);
[A,T0] = jksbxalignx(fname, idx0, ch);
[B,T1] = jksbxalignx(fname, idx1, ch);
Ap = A(151:end-50,151:end-50);
Bp = B(151:end-50,151:end-50);
[u, v] = fftalign(Ap,Bp);
Ar = circshift(A,[u, v]);
m = (Ar+B)/2;
T = [(ones(size(T0,1),1)*[u v] + T0) ; T1];
end