-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsmTrackTrackerIterative.m
108 lines (87 loc) · 3.87 KB
/
fsmTrackTrackerIterative.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function M=fsmTrackTrackerIterative(initM,I,J,threshold,influence, TRACKER, initCorLen)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% If an initializer for the tracker exists, use it to propagate speckle positions at frame I
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 7
initCorLen = Inf;
end
if ~isempty(initM)
% Sort I and make sure there are no empty lines
I=sortrows(I(find(I(:,1)~=0),:));
% Propagate speckle positions
spPos=I(:,1:2); % Extract only positions
pSpPos=fsmTrackPropSpecklePos(spPos,initM,'FORWARD',initCorLen);
% Now I is the propagated version of the original I
I=cat(2,pSpPos,I(:,3)); % Add original intensities to the propagated positions
clear Itmp;
end
if TRACKER == 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Track with the brownian motion tracker with neural network
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mone=fsmTrackTrackerBMTNN(I,J,threshold,influence);
elseif TRACKER == 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Track with linear assignment code
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NONLINK_MARKER = -1; % value to indicate that two points cannot be linked.
extendedTesting = 0;
augmentCC = 1; % automatically generate ghost marker to account for birth and deaths
% Extract speckle coordinates
posI(:,1)=I(:,1);
posI(:,2)=I(:,2);
posJ(:,1)=J(:,1);
posJ(:,2)=J(:,2);
% create cost matrix for the linear assignment code
% in the most general case that is equal to the distance matrix
cc = createSparseDistanceMatrix(posI, posJ, threshold);
%cc = createDistanceMatrix(posI, posJ);
[all_links_1, all_links_2] = lap(cc, NONLINK_MARKER, extendedTesting, augmentCC);
I_N = length(posI);
J_N = length(posJ);
% first get points that are in frame 1 and have a link in frame 2
all_links_1_2 = all_links_1(1:I_N);
frame_1_indices = find(all_links_1_2 <= J_N);
frame_2_indices = all_links_1(frame_1_indices);
Mone = [posI(frame_1_indices,1:2), posJ(frame_2_indices,1:2)];
% Add non-paired speckles from frame 1
frame_1_indices_noLink = find(all_links_1_2 > J_N);
lenNPI=size(frame_1_indices_noLink,1);
MNPI=zeros(lenNPI,4);
MNPI(1:lenNPI,1:2)=posI(frame_1_indices_noLink,1:2);
Mone=cat(1,Mone,MNPI);
% Add non-paired speckles from frame 2
all_links_2_1 = all_links_2(1:J_N);
frame_2_indices_noLink = find(all_links_2_1 > I_N);
lenNPJ=size(frame_2_indices_noLink,1);
MNPJ=zeros(lenNPJ,4);
MNPJ(1:lenNPJ,3:4)=posJ(frame_2_indices_noLink,1:2);
Mone=cat(1,Mone,MNPJ);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% If needed, correct back the propagated coordinates of the first frame
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~isempty(initM)
% Create a copy of Mone
copyMone=Mone;
% Correct back the coordinates of the first frame (= currentM(:,1:2))
for i=1:size(spPos,1)
indx=find(Mone(:,1)==pSpPos(i,1) & Mone(:,2)==pSpPos(i,2));
if length(indx)~=1
error('Propagated position not univocally found in Mone');
end
copyMone(indx,1:2)=spPos(i,:);
end
M=copyMone;
else
% Return the result of the first tracking
M=Mone;
end