-
Notifications
You must be signed in to change notification settings - Fork 3
/
repeated_line_tracking.m
182 lines (158 loc) · 5.35 KB
/
repeated_line_tracking.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function veins = repeated_line_tracking(img, fvr, iterations, r, W)
% Repeated line tracking
% Parameters:
% img - Input vascular image
% fvr - Binary image of the finger region
% iterations - Maximum number of iterations
% r - Distance between tracking point and cross section of the profile
% W - Width of profile
% Returns:
% veins - Vein image
% Reference:
% Feature extraction of finger vein patterns based on repeated line
% tracking and its application to personal identification
% N. Miura, A. Nagasaka, and T. Miyatake
% Machine Vision and Applications, Volume 15, Number 4 (2004), pp. 194--203
% doi: 10.1007/s00138-004-0149-2
p_lr = 0.5; % Probability of goin left or right
p_ud = 0.25; % Probability of going up or down
% writerObj = VideoWriter('peaks.avi');
% open(writerObj);
Tr = zeros(size(img)); % Locus space
bla = [-1,-1; -1,0; -1,1; 0,-1; 0,0; 0,1; 1,-1; 1,0; 1,1];
% Check if W is even
if (mod(W,2) == 0)
disp('Error: W must be odd')
end
ro = round(r*sqrt(2)/2); % r for oblique directions
hW = (W-1)/2; % half width for horz. and vert. directions
hWo = round(hW*sqrt(2)/2); % half width for oblique directions
% Omit unreachable borders
fvr(1:r+hW,:) = 0;
fvr(end-(r+hW-1):end,:) = 0;
fvr(:,1:r+hW) = 0;
fvr(:,end-(r+hW-1):end) = 0;
%% Uniformly distributed starting points
indices = find(fvr > 0);
a = randperm(length(indices));
a = a(1:iterations); % Limit to number of iterations
[ys, xs] = ind2sub(size(img), indices(a));
%ys = [200;20];% LET OP
%xs= [200;200];% LET OP
%% Iterate through all starting points
for it = 1:size(ys,1)
xc = xs(it); % Current tracking point, x
yc = ys(it); % Current tracking point, y
% Determine the moving-direction attributes
% Going left or right ?
if rand() >= 0.5
Dlr = -1; % Going left
else
Dlr = 1; % Going right
end
% Going up or down ?
if rand() >= 0.5
Dud = -1; % Going up
else
Dud = 1; % Going down
end
% Initialize locus-positition table Tc
Tc = false(size(img));
%Dlr = -1; Dud=-1;% LET OP
Vl = 1;
while Vl > 0;
%% Determine the moving candidate point set Nc
Nr = false(3);
Rnd = rand();
%Rnd = 0.8;% LET OP
if Rnd < p_lr
% Going left or right
Nr(:,2+Dlr) = true;
elseif (Rnd >= p_lr) && (Rnd < p_lr + p_ud)
% Going up or down
Nr(2+Dud,:) = true;
else
% Going any direction
Nr = true(3);
Nr(2,2) = false;
end
tmp = find( ~Tc(yc-1:yc+1,xc-1:xc+1) & Nr & fvr(yc-1:yc+1,xc-1:xc+1) );
Nc =[xc + bla(tmp,1), yc + bla(tmp,2)];
if size(Nc,1)==0
Vl=-1;
continue
end
%% Detect dark line direction near current tracking point
Vdepths = zeros(size(Nc,1),1); % Valley depths
for i = 1:size(Nc,1)
% Horizontal or vertical
if Nc(i,2) == yc
% Horizontal plane
yp = Nc(i,2);
if Nc(i,1) > xc
% Right direction
xp = Nc(i,1) + r;
else
% Left direction
xp = Nc(i,1) - r;
end
Vdepths(i) = img(yp + hW, xp) - ...
2*img(yp,xp) + ...
img(yp - hW, xp);
elseif Nc(i,1) == xc
% Vertical plane
xp = Nc(i,1);
if Nc(i,2) > yc
% Down direction
yp = Nc(i,2) + r;
else
% Up direction
yp = Nc(i,2) - r;
end
Vdepths(i) = img(yp, xp + hW) - ...
2*img(yp,xp) + ...
img(yp, xp - hW);
end
% Oblique directions
if ((Nc(i,1) > xc) && (Nc(i,2) < yc)) || ((Nc(i,1) < xc) && (Nc(i,2) > yc))
% Diagonal, up /
if Nc(i,1) > xc && Nc(i,2) < yc
% Top right
xp = Nc(i,1) + ro;
yp = Nc(i,2) - ro;
else
% Bottom left
xp = Nc(i,1) - ro;
yp = Nc(i,2) + ro;
end
Vdepths(i) = img(yp - hWo, xp - hWo) - ...
2*img(yp,xp) + ...
img(yp + hWo, xp + hWo);
else
% Diagonal, down \
if Nc(i,1) < xc && Nc(i,2) < yc
% Top left
xp = Nc(i,1) - ro;
yp = Nc(i,2) - ro;
else
% Bottom right
xp = Nc(i,1) + ro;
yp = Nc(i,2) + ro;
end
Vdepths(i) = img(yp + hWo, xp - hWo) - ...
2*img(yp,xp) + ...
img(yp - hWo, xp + hWo);
end
end % End search of candidates
[~, index] = max(Vdepths); % Determine best candidate
% Register tracking information
Tc(yc, xc) = true;
% Increase value of tracking space
Tr(yc, xc) = Tr(yc, xc) + 1;
%writeVideo(writerObj,Tr);
% Move tracking point
xc = Nc(index, 1);
yc = Nc(index, 2);
end
end
veins = Tr;