forked from kevinlisun/clothes_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMD.m
90 lines (73 loc) · 1.89 KB
/
EMD.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
function emd_value = emd(videoP, videoQ, type_distance)%, videoP_weight = 0, videoQ_weight = 0)
[n, P_frames, feat_P] = size(videoP);
[n, Q_frames, feat_Q] = size(videoQ);
emd_value = -1;
method = 1;
if feat_P == feat_Q
% if videoP_weight = 0
videoP_weight = ones(P_frames,1)/P_frames;
n_tableP = 4;
% end
% if videoQ_weight = 0
videoQ_weight = ones(Q_frames,1)/Q_frames;
n_tableQ = 4;
% end
emd_value = 0;
if method ==1
for i=1:P_frames
j=i;
% for j=1:Q_frames
fij = min(videoP_weight(i), videoQ_weight(j));
v1=videoP(1,i,:);
v1 = reshape(v1,[1 length(v1)]);
v2=videoQ(1,j,:);
v2 = reshape(v2,[1 length(v2)]);
v1 = real (v1);
v2 = real (v2);
euclidean_dist = pdist([v1; v2], type_distance);
fij_hat= fij*sum(euclidean_dist);
emd_value = emd_value + fij_hat;
% end
end
elseif method ==2
for i=1:n_tableP
for j=1:n_tableQ
fij = min(videoP_weight(i), videoQ_weight(j));
v1=videoP(1,i,:);
v1 = reshape(v1,[1 length(v1)]);
v2=videoQ(1,j,:);
v2 = reshape(v2,[1 length(v2)]);
euclidean_dist = pdist([v1; v2]);
fij_hat= fij*sum(euclidean_dist);
emd_value = emd_value + fij_hat;
end
end
for i=n_tableP+1:P_frames
for j=n_tableQ+1:Q_frames
fij = min(videoP_weight(i), videoQ_weight(j));
v1=videoP(1,i,:);
v1 = reshape(v1,[1 length(v1)]);
v2=videoQ(1,j,:);
v2 = reshape(v2,[1 length(v2)]);
euclidean_dist = pdist([v1; v2]);
fij_hat= fij*sum(euclidean_dist);
emd_value = emd_value + fij_hat;
end
end
elseif method ==3
for i=1:P_frames
for j=1:Q_frames
fij = min(videoP_weight(i), videoQ_weight(j));
v1=videoP(1,i,:);
v1 = reshape(v1,[1 length(v1)]);
v2=videoQ(1,j,:);
v2 = reshape(v2,[1 length(v2)]);
v1
v2
euclidean_dist = pdist([v1; v2]);
fij_hat= fij*sum(euclidean_dist);
emd_value = emd_value + fij_hat;
end
end
end
end