-
Notifications
You must be signed in to change notification settings - Fork 0
/
jkfovmatch_previousSession.m
76 lines (64 loc) · 2.35 KB
/
jkfovmatch_previousSession.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
% pwd
close all
num_iter = 15;
mouse_num = '053';
layer = 1;
ref_fn_list = {'052_S01_000','053_S01_000','054_S01_000','056_S01_000'};
for i = 1 : length(ref_fn_list1)
if strfind(ref_fn_list{i},mouse_num) == 1
ref_fn = ref_fn_list{i};
break
end
end
cd(['d:\2p\JK\',ref_fn(1:3)])
if ~exist([ref_fn,'.align'], 'file')
jksbxaligndir(ref_fn)
end
load([ref_fn,'.align'], '-mat')
if layer == 1
ref1 = mat2gray(m1{1});
ref2 = mat2gray(m2{1});
else
ref1 = mat2gray(m1{5});
ref2 = mat2gray(m2{5});
end
% figure(1), imagesc(ref1(101:end-10,101:end-10)), axis image,
figure, imshow(mat2gray(ref1)), axis image
mmfile = memmapfile('scanbox.mmap','Writable',true, ...
'Format', { 'int16' [1 16] 'header' } , 'Repeat', 1);
fh1 = figure;
while(true)
while(mmfile.Data.header(1)<0) % wait for a new frame...
if(mmfile.Data.header(1) == -2) % exit if Scanbox stopped
return;
end
end
mchA = [];
mchB = [];
for i = 1 : num_iter
mmfile.Format = {'int16' [1 16] 'header' ; ...
'uint16' double([mmfile.Data.header(2) mmfile.Data.header(3)]) 'chA';...
'uint16' double([mmfile.Data.header(2) mmfile.Data.header(3)]) 'chB'};
if i == 1
mchA = double(intmax('uint16')-mmfile.Data.chA);
mchB = double(intmax('uint16')-mmfile.Data.chB);
mfinalA = mchA;
mfinalB = mchB;
else
prev_mchA = mfinalA;
mchA = double(intmax('uint16')-mmfile.Data.chA);
[u1, v1] = jkfftalign(mchA(50:end-50,50:end-50),prev_mchA(50:end-50,50:end-50));
mchA = circshift(mchA,[u1,v1]);
mfinalA = mfinalA + mchA/num_iter;
prev_mchB = mfinalB;
mchB = double(intmax('uint16')-mmfile.Data.chB);
[u1, v1] = jkfftalign(mchB(50:end-50,50:end-50),prev_mchB(50:end-50,50:end-50));
mchB = circshift(mchB,[u1,v1]);
mfinalB = mfinalB + mchB/num_iter;
end
mmfile.Data.header(1) = -1; % signal Scanbox that frame has been consumed!
end
subplot(121),imshowpair(mfinalA(101:end-10,101:end-10),ref1(101:end-10,101:end-10)), axis image,
subplot(122),imshowpair(mfinalB(101:end-10,101:end-10),ref2(101:end-10,101:end-10)), axis image,
drawnow limitrate;
end