-
Notifications
You must be signed in to change notification settings - Fork 22
/
fun_preprocess_klt.m
executable file
·139 lines (126 loc) · 5.63 KB
/
fun_preprocess_klt.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
function trks_new = fun_preprocess_klt(trks, delete_th1, delete_th2, delete_th3)
trks_new = trks;
tr_num = 1; tr_num2 = 1;
%% Delete
while tr_num <= length(trks_new)
if ~isempty(delete_th1)
if length(trks_new(tr_num).x) <= delete_th1 || (trks_new(tr_num).x(1) == trks_new(tr_num).x(end) && ...
trks_new(tr_num).y(1) == trks_new(tr_num).y(end)) || ...
(sqrt((trks_new(tr_num).x(end)- trks_new(tr_num).x(1))^2 + ...
(trks_new(tr_num).y(end)-trks_new(tr_num).y(1))^2) < delete_th2)
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
% delete the data of x&y both unchange
trks_new(tr_num) = [];
tr_num = tr_num - 1;
elseif length(trks_new(tr_num).t) ~= (trks_new(tr_num).t(end)-trks_new(tr_num).t(1)+1)
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
else
% delete the data of small change
count = 0;
for t = 1 :length(trks_new(tr_num).y)-1
if trks_new(tr_num).y(t+1) == trks_new(tr_num).y(t) && ...
trks_new(tr_num).x(t+1) == trks_new(tr_num).x(t)
continue;
end
count = count + 1;
end
if count < length(trks_new(tr_num).y)/3
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
else
% new1: delete repeat
for t = 1 : length(trks_new(tr_num).y)-3
same_n = t;
while same_n+1 < length(trks_new(tr_num).y) && ...
abs(trks_new(tr_num).y(same_n+2)-trks_new(tr_num).y(same_n)) < 1 && ...
abs(trks_new(tr_num).x(same_n+2)-trks_new(tr_num).x(same_n)) < 1
% while same_n+3 < length(trks_new(tr_num).y) && ...
% abs(trks_new(tr_num).y(same_n+2)-trks_new(tr_num).y(same_n)) < 2 && ...
% abs(trks_new(tr_num).x(same_n+2)-trks_new(tr_num).x(same_n)) < 2
same_n = same_n + 1;
end
if same_n-t > delete_th3
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
break;
end
end
end
end
else
if (trks_new(tr_num).x(1) == trks_new(tr_num).x(end) && ...
trks_new(tr_num).y(1) == trks_new(tr_num).y(end)) || ...
(sqrt((trks_new(tr_num).x(end)- trks_new(tr_num).x(1))^2 + ...
(trks_new(tr_num).y(end)-trks_new(tr_num).y(1))^2) < delete_th2)
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
% delete the data of x&y both unchange
trks_new(tr_num) = [];
tr_num = tr_num - 1;
elseif length(trks_new(tr_num).t) ~= (trks_new(tr_num).t(end)-trks_new(tr_num).t(1)+1)
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
else
% delete the data of small change
count = 0;
for t = 1 :length(trks_new(tr_num).y)-1
if trks_new(tr_num).y(t+1) == trks_new(tr_num).y(t) && ...
trks_new(tr_num).x(t+1) == trks_new(tr_num).x(t)
continue;
end
count = count + 1;
end
if count < length(trks_new(tr_num).y)/3
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
else
% new1: delete repeat
for t = 1 : length(trks_new(tr_num).y)-3
same_n = t;
while same_n+1 < length(trks_new(tr_num).y) && ...
abs(trks_new(tr_num).y(same_n+2)-trks_new(tr_num).y(same_n)) < 1 && ...
abs(trks_new(tr_num).x(same_n+2)-trks_new(tr_num).x(same_n)) < 1
% while same_n+3 < length(trks_new(tr_num).y) && ...
% abs(trks_new(tr_num).y(same_n+2)-trks_new(tr_num).y(same_n)) < 2 && ...
% abs(trks_new(tr_num).x(same_n+2)-trks_new(tr_num).x(same_n)) < 2
same_n = same_n + 1;
end
if same_n-t > delete_th3
%
trks_short(tr_num2) = trks_new(tr_num);
tr_num2 = tr_num2 + 1;
%
trks_new(tr_num) = [];
tr_num = tr_num - 1;
break;
end
end
end
end
end
tr_num = tr_num + 1;
end