-
Notifications
You must be signed in to change notification settings - Fork 13
/
LDP_func.m
123 lines (106 loc) · 4.17 KB
/
LDP_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
function [hist_LDP_u2,hist_LDP_u2_convex_up,hist_LDP_u2_convex_down] = LDP_func(image,window_size,thres)
[row,col]=size(image);
evm = evm_full(image,window_size);
evm = evm(2:end-1,2:end-1);
dir_0 = conv2(image,[-1 1],'same');
dir_45 = conv2(image,[0 1;-1 0],'same');
dir_90 = conv2(image,[1 ; -1],'same');
dir_135 = conv2(image,[-1 0;0 1],'same');
%% Calculate LDP Pattern for 0 degree direction
% Append all 8-neighborhood to a single matrix
LDP_i = dir_0;
neigh_mtx=zeros(row-2,col-2,8);
cent_mtx=LDP_i(2:end-1,2:end-1);
neigh_mtx(:,:,1)=LDP_i(1:row-2,1:col-2);
neigh_mtx(:,:,2)=LDP_i(1:row-2,2:col-1);
neigh_mtx(:,:,3)=LDP_i(1:row-2,3:col);
neigh_mtx(:,:,4)=LDP_i(2:row-1,3:col);
neigh_mtx(:,:,5)=LDP_i(3:row,3:col);
neigh_mtx(:,:,6)=LDP_i(3:row,2:col-1);
neigh_mtx(:,:,7)=LDP_i(3:row,1:col-2);
neigh_mtx(:,:,8)=LDP_i(2:row-1,1:col-2);
cent_mtx_rep=repmat(cent_mtx,[1,1,8]);
mapping=getmapping(8,'u2');
LDP_temp=neigh_mtx>=cent_mtx_rep;
LDP_code_i=zeros(row-2,col-2);
for neighbor=1:8
LDP_code_i=LDP_code_i+2^(neighbor-1)*LDP_temp(:,:,neighbor);
end
LDP_u2_i=mapping.table(LDP_code_i+1);
hist_LDP_u2_0=hist(LDP_u2_i(:),0:58);
hist_LDP_u2_convex_up_0=hist(LDP_u2_i(evm>=thres),0:58);
hist_LDP_u2_convex_down_0=hist(LDP_u2_i(evm<thres),0:58);
%% Calculate LDP Pattern for 45 degree direction
% Append all 8-neighborhood to a single matrix
LDP_i = dir_45;
neigh_mtx=zeros(row-2,col-2,8);
cent_mtx=LDP_i(2:end-1,2:end-1);
neigh_mtx(:,:,1)=LDP_i(1:row-2,1:col-2);
neigh_mtx(:,:,2)=LDP_i(1:row-2,2:col-1);
neigh_mtx(:,:,3)=LDP_i(1:row-2,3:col);
neigh_mtx(:,:,4)=LDP_i(2:row-1,3:col);
neigh_mtx(:,:,5)=LDP_i(3:row,3:col);
neigh_mtx(:,:,6)=LDP_i(3:row,2:col-1);
neigh_mtx(:,:,7)=LDP_i(3:row,1:col-2);
neigh_mtx(:,:,8)=LDP_i(2:row-1,1:col-2);
cent_mtx_rep=repmat(cent_mtx,[1,1,8]);
LDP_temp=neigh_mtx>=cent_mtx_rep;
LDP_code_i=zeros(row-2,col-2);
for neighbor=1:8
LDP_code_i=LDP_code_i+2^(neighbor-1)*LDP_temp(:,:,neighbor);
end
LDP_u2_i=mapping.table(LDP_code_i+1);
hist_LDP_u2_45=hist(LDP_u2_i(:),0:58);
hist_LDP_u2_convex_up_45=hist(LDP_u2_i(evm>=thres),0:58);
hist_LDP_u2_convex_down_45=hist(LDP_u2_i(evm<thres),0:58);
%% Calculate LDP Pattern for 90 degree direction
% Append all 8-neighborhood to a single matrix
LDP_i = dir_90;
neigh_mtx=zeros(row-2,col-2,8);
cent_mtx=LDP_i(2:end-1,2:end-1);
neigh_mtx(:,:,1)=LDP_i(1:row-2,1:col-2);
neigh_mtx(:,:,2)=LDP_i(1:row-2,2:col-1);
neigh_mtx(:,:,3)=LDP_i(1:row-2,3:col);
neigh_mtx(:,:,4)=LDP_i(2:row-1,3:col);
neigh_mtx(:,:,5)=LDP_i(3:row,3:col);
neigh_mtx(:,:,6)=LDP_i(3:row,2:col-1);
neigh_mtx(:,:,7)=LDP_i(3:row,1:col-2);
neigh_mtx(:,:,8)=LDP_i(2:row-1,1:col-2);
cent_mtx_rep=repmat(cent_mtx,[1,1,8]);
LDP_temp=neigh_mtx>=cent_mtx_rep;
LDP_code_i=zeros(row-2,col-2);
for neighbor=1:8
LDP_code_i=LDP_code_i+2^(neighbor-1)*LDP_temp(:,:,neighbor);
end
LDP_u2_i=mapping.table(LDP_code_i+1);
hist_LDP_u2_90=hist(LDP_u2_i(:),0:58);
hist_LDP_u2_convex_up_90=hist(LDP_u2_i(evm>=thres),0:58);
hist_LDP_u2_convex_down_90=hist(LDP_u2_i(evm<thres),0:58);
%% Calculate LDP Pattern for 135 degree direction
% Append all 8-neighborhood to a single matrix
LDP_i = dir_135;
neigh_mtx=zeros(row-2,col-2,8);
cent_mtx=LDP_i(2:end-1,2:end-1);
neigh_mtx(:,:,1)=LDP_i(1:row-2,1:col-2);
neigh_mtx(:,:,2)=LDP_i(1:row-2,2:col-1);
neigh_mtx(:,:,3)=LDP_i(1:row-2,3:col);
neigh_mtx(:,:,4)=LDP_i(2:row-1,3:col);
neigh_mtx(:,:,5)=LDP_i(3:row,3:col);
neigh_mtx(:,:,6)=LDP_i(3:row,2:col-1);
neigh_mtx(:,:,7)=LDP_i(3:row,1:col-2);
neigh_mtx(:,:,8)=LDP_i(2:row-1,1:col-2);
cent_mtx_rep=repmat(cent_mtx,[1,1,8]);
LDP_temp=neigh_mtx>=cent_mtx_rep;
LDP_code_i=zeros(row-2,col-2);
for neighbor=1:8
LDP_code_i=LDP_code_i+2^(neighbor-1)*LDP_temp(:,:,neighbor);
end
LDP_u2_i=mapping.table(LDP_code_i+1);
hist_LDP_u2_135=hist(LDP_u2_i(:),0:58);
hist_LDP_u2_convex_up_135=hist(LDP_u2_i(evm>=thres),0:58);
hist_LDP_u2_convex_down_135=hist(LDP_u2_i(evm<thres),0:58);
% Concatenate LDP patterns
hist_LDP_u2=[hist_LDP_u2_0 hist_LDP_u2_45 hist_LDP_u2_90 hist_LDP_u2_135];
hist_LDP_u2_convex_up=[hist_LDP_u2_convex_up_0 hist_LDP_u2_convex_up_45 hist_LDP_u2_convex_up_90 hist_LDP_u2_convex_up_135];
hist_LDP_u2_convex_down=[hist_LDP_u2_convex_down_0 hist_LDP_u2_convex_down_45 hist_LDP_u2_convex_down_90 hist_LDP_u2_convex_down_135];
end