-
Notifications
You must be signed in to change notification settings - Fork 13
/
LTrP_func.m
210 lines (180 loc) · 8.42 KB
/
LTrP_func.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
function [hist_LTrP_u2,hist_LTrP_u2_convex_up,hist_LTrP_u2_convex_down] = LTrP_func(image,window_size,thres)
[row,col]=size(image);
evm = evm_full(image,window_size);
evm = evm(2:end-2,2:end-2);
temp = conv2(image,[1 -1]);
diff_x_0 = temp(:,2:end)>0;
temp = -1*conv2(image,[-1 1]);
diff_x_180 = temp(:,1:end-1)>0;
temp = -1*conv2(image,[-1 ;1]);
diff_y_270 = temp(2:end,:)>0;
temp = -1*conv2(image,[1 ;-1]);
diff_y_90 = temp(1:end-1,:)>0;
pat_x_0_y_90 = diff_x_0 + 2*diff_y_90;
pat_x_0_y_270 = diff_x_0 + 2*diff_y_270;
pat_x_180_y_90 = diff_x_180 + 2*diff_y_90;
pat_x_180_y_270 = diff_x_180 + 2*diff_y_270;
%% Calculate LTrP Pattern for 0 degree and 90 degree direction (derivative along Postive x axis and Positive y axis)
% Append all 8-neighborhood to a single matrix
pat_i_y = pat_x_0_y_90;
neigh_mtx=zeros(row-3,col-3,8);
neigh_mtx(:,:,1)=pat_i_y(2:row-2,2:col-2);
neigh_mtx(:,:,2)=pat_i_y(2:row-2,3:col-1);
neigh_mtx(:,:,3)=pat_i_y(2:row-2,4:col);
neigh_mtx(:,:,4)=pat_i_y(3:row-1,4:col);
neigh_mtx(:,:,5)=pat_i_y(4:row,4:col);
neigh_mtx(:,:,6)=pat_i_y(4:row,3:col-1);
neigh_mtx(:,:,7)=pat_i_y(4:row,2:col-2);
neigh_mtx(:,:,8)=pat_i_y(3:row-1,2:col-2);
mapping=getmapping(8,'u2');
neigh_mtx_temp = neigh_mtx == 1;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_90_1=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_90_1_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_90_1_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 2;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_90_2=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_90_2_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_90_2_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 3;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_90_3=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_90_3_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_90_3_convex_up=hist(LTrP_u2(evm<thres),0:58);
%% Calculate LTrP Pattern for 0 degree and 270 degree direction (derivative along Postive x axis and Negative y axis)
% Append all 8-neighborhood to a single matrix
pat_i_y = pat_x_0_y_270;
neigh_mtx=zeros(row-3,col-3,8);
neigh_mtx(:,:,1)=pat_i_y(2:row-2,2:col-2);
neigh_mtx(:,:,2)=pat_i_y(2:row-2,3:col-1);
neigh_mtx(:,:,3)=pat_i_y(2:row-2,4:col);
neigh_mtx(:,:,4)=pat_i_y(3:row-1,4:col);
neigh_mtx(:,:,5)=pat_i_y(4:row,4:col);
neigh_mtx(:,:,6)=pat_i_y(4:row,3:col-1);
neigh_mtx(:,:,7)=pat_i_y(4:row,2:col-2);
neigh_mtx(:,:,8)=pat_i_y(3:row-1,2:col-2);
mapping=getmapping(8,'u2');
neigh_mtx_temp = neigh_mtx == 1;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_270_1=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_270_1_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_270_1_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 2;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_270_2=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_270_2_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_270_2_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 3;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_0_270_3=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_0_270_3_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_0_270_3_convex_up=hist(LTrP_u2(evm<thres),0:58);
%% Calculate LTrP Pattern for 180 degree and 90 degree direction (derivative along Negative x axis and Positive y axis)
% Append all 8-neighborhood to a single matrix
pat_i_y = pat_x_180_y_90;
neigh_mtx=zeros(row-3,col-3,8);
neigh_mtx(:,:,1)=pat_i_y(2:row-2,2:col-2);
neigh_mtx(:,:,2)=pat_i_y(2:row-2,3:col-1);
neigh_mtx(:,:,3)=pat_i_y(2:row-2,4:col);
neigh_mtx(:,:,4)=pat_i_y(3:row-1,4:col);
neigh_mtx(:,:,5)=pat_i_y(4:row,4:col);
neigh_mtx(:,:,6)=pat_i_y(4:row,3:col-1);
neigh_mtx(:,:,7)=pat_i_y(4:row,2:col-2);
neigh_mtx(:,:,8)=pat_i_y(3:row-1,2:col-2);
mapping=getmapping(8,'u2');
neigh_mtx_temp = neigh_mtx == 1;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_90_1=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_90_1_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_90_1_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 2;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_90_2=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_90_2_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_90_2_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 3;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_90_3=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_90_3_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_90_3_convex_up=hist(LTrP_u2(evm<thres),0:58);
%% Calculate LTrP Pattern for 180 degree and 270 degree direction (derivative along Negative x axis and Negative y axis)
% Append all 8-neighborhood to a single matrix
pat_i_y = pat_x_180_y_270;
neigh_mtx=zeros(row-3,col-3,8);
neigh_mtx(:,:,1)=pat_i_y(2:row-2,2:col-2);
neigh_mtx(:,:,2)=pat_i_y(2:row-2,3:col-1);
neigh_mtx(:,:,3)=pat_i_y(2:row-2,4:col);
neigh_mtx(:,:,4)=pat_i_y(3:row-1,4:col);
neigh_mtx(:,:,5)=pat_i_y(4:row,4:col);
neigh_mtx(:,:,6)=pat_i_y(4:row,3:col-1);
neigh_mtx(:,:,7)=pat_i_y(4:row,2:col-2);
neigh_mtx(:,:,8)=pat_i_y(3:row-1,2:col-2);
mapping=getmapping(8,'u2');
neigh_mtx_temp = neigh_mtx == 1;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_270_1=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_270_1_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_270_1_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 2;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_270_2=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_270_2_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_270_2_convex_up=hist(LTrP_u2(evm<thres),0:58);
neigh_mtx_temp = neigh_mtx == 3;
LTrP_code_i_y=zeros(row-3,col-3);
for neighbor=1:8
LTrP_code_i_y=LTrP_code_i_y+2^(neighbor-1)*neigh_mtx_temp(:,:,neighbor);
end
LTrP_u2=mapping.table(LTrP_code_i_y+1);
hist_LTrP_u2_180_270_3=hist(LTrP_u2(:),0:58);
hist_LTrP_u2_180_270_3_convex_down=hist(LTrP_u2(evm>=thres),0:58);
hist_LTrP_u2_180_270_3_convex_up=hist(LTrP_u2(evm<thres),0:58);
hist_LTrP_u2 = [hist_LTrP_u2_0_90_1 hist_LTrP_u2_0_90_2 hist_LTrP_u2_0_90_3 hist_LTrP_u2_180_270_1 hist_LTrP_u2_180_270_2 hist_LTrP_u2_180_270_3 hist_LTrP_u2_180_90_1 hist_LTrP_u2_180_90_2 hist_LTrP_u2_180_90_3 hist_LTrP_u2_0_270_1 hist_LTrP_u2_0_270_2 hist_LTrP_u2_0_270_3];
hist_LTrP_u2_convex_down = [hist_LTrP_u2_0_90_1_convex_down hist_LTrP_u2_0_90_2_convex_down hist_LTrP_u2_0_90_3_convex_down hist_LTrP_u2_180_270_1_convex_down hist_LTrP_u2_180_270_2_convex_down hist_LTrP_u2_180_270_3_convex_down hist_LTrP_u2_180_90_1_convex_down hist_LTrP_u2_180_90_2_convex_down hist_LTrP_u2_180_90_3_convex_down hist_LTrP_u2_0_270_1_convex_down hist_LTrP_u2_0_270_2_convex_down hist_LTrP_u2_0_270_3_convex_down];
hist_LTrP_u2_convex_up = [hist_LTrP_u2_0_90_1_convex_up hist_LTrP_u2_0_90_2_convex_up hist_LTrP_u2_0_90_3_convex_up hist_LTrP_u2_180_270_1_convex_up hist_LTrP_u2_180_270_2_convex_up hist_LTrP_u2_180_270_3_convex_up hist_LTrP_u2_180_90_1_convex_up hist_LTrP_u2_180_90_2_convex_up hist_LTrP_u2_180_90_3_convex_up hist_LTrP_u2_0_270_1_convex_up hist_LTrP_u2_0_270_2_convex_up hist_LTrP_u2_0_270_3_convex_up];
end