forked from meshgi/Histogram_of_Color_Advancements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RUNME.m
346 lines (280 loc) · 10.9 KB
/
RUNME.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
% Similarities of one person, named Intra-object similarity, are calculated on
% consecutice frames of this subject. On the other side, similarities (here: dissimilarities)
% between different objects, named Inter-object similarity, are computed
% on the subject images of the same frame.
% intra subject similarity r: obj1 g: obj2: b: obj3
% inter subject similarity k: obj1:obj2 m: obj2:obj3 c: obj1:obj3
addpath(genpath('.'));
clc
clear
close all
option_verbose = false;
obj_cnt = 3;
% =========================================================================
% colorspace_name = 'rgb';
% colorspace_name = 'hsv';
% colorspace_name = 'ycbcr';
% colorspace_name = 'XYZ';
% colorspace_name = 'lab';
colorspace_name = 'gray';
% =========================================================================
% hoc_name = 'conventional'; hoc_param = [8,8,4];
hoc_name = 'clustering'; hoc_param = [40 , 1]; % [bin count , sorting enabled]
% hoc_name = 'marg-moments'; hoc_param = [];
% hoc_name = 'conventional,g2,avg'; hoc_param = 5;
% hoc_name = 'clustering,g2,avg'; hoc_param = 40;
% hoc_name = 'conventional,g3,avg'; hoc_param = 5;
% hoc_name = 'clustering,g3,avg'; hoc_param = 40;
% hoc_name = 'conventional,g5,avg'; hoc_param = 5;
% hoc_name = 'clustering,g5,avg'; hoc_param = 40;
% hoc_name = 'conventional,g2,wei'; hoc_param = 5;
% hoc_name = 'clustering,g2,wei'; hoc_param = 40;
% hoc_name = 'conventional,g3,wei'; hoc_param = 5;
% hoc_name = 'clustering,g3,wei'; hoc_param = 40;
% hoc_name = 'conventional,g5,wei'; hoc_param = 5;
% hoc_name = 'clustering,g5,wei'; hoc_param = 40;
% hoc_name = 'conventional,g2'; hoc_param = 5;
% hoc_name = 'clustering,g2'; hoc_param = 40;
% hoc_name = 'conventional,g3'; hoc_param = 5;
% hoc_name = 'clustering,g3'; hoc_param = 40;
% hoc_name = 'conventional,g5'; hoc_param = 5;
% hoc_name = 'clustering,g5'; hoc_param = 40;
% =========================================================================
hoc_update = 'none';
% hoc_update = 'moving average';
% hoc_update = 'nerd';
% hoc_update = 'last 5';
% hoc_update = 'average all';
% hoc_update = 'update with memory';
% hoc_update = 'bhat';
% =========================================================================
% hoc_dist_name = 'L1';
hoc_dist_name = 'L2';
% hoc_dist_name = 'Linf';
% hoc_dist_name = 'correlation';
% hoc_dist_name = 'chi-square';
% hoc_dist_name = 'intersection';
% hoc_dist_name = 'bhattacharyya';
% hoc_dist_name = 'kl-divergance';
% hoc_dist_name = 'diffusion';
% hoc_dist_name = 'match';
% hoc_dist_name = 'jeffry div';
% hoc_dist_name = 'kolmogorov smirnov';
% hoc_dist_name = 'cramer von mises';
% hoc_dist_name = 'quadratic';
% hoc_dist_name = 'quadratic-chi';
% hoc_dist_name = 'emd hat';
% hoc_dist_name = 'cosine';
% hoc_dist_name = 'L0';
% hoc_dist_name = 'noticeable';
% hoc_dist_name = 'fractional';
% hoc_dist_name = 'canberra';
% hoc_dist_name = 'L1,avg';
% hoc_dist_name = 'L2,avg';
% hoc_dist_name = 'Linf,avg';
% hoc_dist_name = 'correlation,avg';
% hoc_dist_name = 'chi-square,avg';
% hoc_dist_name = 'intersection,avg';
% hoc_dist_name = 'bhattacharyya,avg';
% hoc_dist_name = 'kl-divergance,avg';
% hoc_dist_name = 'diffusion,avg';
% hoc_dist_name = 'match,avg';
% hoc_dist_name = 'jeffry div,avg';
% hoc_dist_name = 'kolmogorov smirnov,avg';
% hoc_dist_name = 'cramer von mises,avg';
% hoc_dist_name = 'quadratic,avg';
% hoc_dist_name = 'quadratic-chi,avg';
% hoc_dist_name = 'emd hat,avg';
% hoc_dist_name = 'cosine,avg';
% hoc_dist_name = 'L1,wei';
% hoc_dist_name = 'L2,wei';
% hoc_dist_name = 'Linf,wei';
% hoc_dist_name = 'correlation,wei';
% hoc_dist_name = 'chi-square,wei';
% hoc_dist_name = 'intersection,wei';
% hoc_dist_name = 'bhattacharyya,wei';
% hoc_dist_name = 'kl-divergance,wei';
% hoc_dist_name = 'diffusion,wei';
% hoc_dist_name = 'match,wei';
% hoc_dist_name = 'jeffry div,wei';
% hoc_dist_name = 'kolmogorov smirnov,wei';
% hoc_dist_name = 'cramer von mises,wei';
% hoc_dist_name = 'quadratic,wei';
% hoc_dist_name = 'quadratic-chi,wei';
% hoc_dist_name = 'emd hat,wei';
% hoc_dist_name = 'cosine,wei';
% =========================================================================
% read all file names
disp('Loading Data...');
for i = 1:obj_cnt
obj_img_list{i} = dir(['data/scenario 1/obj' num2str(i) '/*.jpg']);
obj_msk_list{i} = dir(['data/scenario 1/obj' num2str(i) '/*.bmp']);
end
n = length(obj_img_list{1,1});
[ctrs,q] = hoc_init ( hoc_name , imread('data/scenario 1/frame_0455.jpg'), hoc_param , colorspace_name);
for o = 1:obj_cnt
disp (['Calculating HOC for Obj ' num2str(o)]);
for i = 1:n
img = imread(['data/scenario 1/obj' num2str(o) '/' obj_img_list{1,o}(i).name]);
msk = imread(['data/scenario 1/obj' num2str(o) '/' obj_msk_list{1,o}(i).name]);
r = fg_bg_ratio ( hoc_name , msk );
h = hoc ( hoc_name , img , ctrs , r , colorspace_name);
frame_obj{i,o}.img = img;
frame_obj{i,o}.msk = msk;
frame_obj{i,o}.hoc = h;
frame_obj{i,o}.rat = r;
end
end
%% Intra Similarity
intra_sim = zeros(1,n-1);
for o = 1:obj_cnt
disp(['Obj' num2str(o) ' Intra Similarity Calculation.'] );
for i = 2:n
hoc1 = frame_obj{i,o}.hoc; % this frame
hoc2 = frame_obj{i-1,o}.hoc; % last frame
cof1 = frame_obj{i,o}.rat; % this frame
cof2 = frame_obj{i-1,o}.rat; % last frame
% visualization of hoc differences
if (option_verbose)
clf;
subplot (3,3,[1,2]); hist_vis (hoc1,ctrs);
subplot (3,3,[4,5]); hist_vis (hoc2,ctrs);
subplot (3,3,3); imshow(frame_obj{i,o}.img);
subplot (3,3,6); imshow(frame_obj{i-1,o}.img);
subplot (3,3,[7,8]); bar (abs(hoc1-hoc2)); xlim([0 length(hoc1)]); ylim([0 0.2]); drawnow;
end
intra_sim (o,i-1) = hoc_distance ( hoc_dist_name, hoc1, hoc2, cof1 , cof2 , q);
end
% plot (1:n-1 , intra_sim(o,:),colors{1,o},'LineWidth',2);
% hold on
end
% hold off
%% Inter Similarity
inter_sim = zeros (obj_cnt,obj_cnt,n);
for o1 = 1:obj_cnt
for o2 = o1+1:obj_cnt
disp(['Obj' num2str(o1) ' and Obj' num2str(o2) ' Inter Similarity Calculation.'] );
for i = 1:n
hoc1 = frame_obj{i,o1}.hoc; % obj 1
hoc2 = frame_obj{i,o2}.hoc; % obj 2
cof1 = frame_obj{i,o1}.rat; % obj 1
cof2 = frame_obj{i,o2}.rat; % obj 2
inter_sim (o1,o2,i) = hoc_distance ( hoc_dist_name, hoc1, hoc2, cof1, cof2 , q);
inter_sim (o2,o1,i) = inter_sim (o1,o2,i);
end
end
end
%% Template Matching
template_sim = zeros(1,n-1);
for o = 1:obj_cnt
hoc2 = frame_obj{1,o}.hoc; % template
cof2 = frame_obj{1,o}.rat; % template
disp(['Obj' num2str(o) ' Template Similarity Calculation.'] );
for i = 2:n
hoc1 = frame_obj{i,o}.hoc; % this frame
rat1 = frame_obj{i,o}.rat; % this frame
% visualization of hoc differences
if (option_verbose)
clf;
subplot (3,3,[1,2]); hist_vis (hoc1,ctrs);
subplot (3,3,[4,5]); hist_vis (hoc2,ctrs);
subplot (3,3,3); imshow(frame_obj{i,o}.img);
subplot (3,3,6); imshow(frame_obj{1,o}.img);
subplot (3,3,[7,8]); bar (abs(hoc1-hoc2)); xlim([0 length(hoc1)]); ylim([0 0.2]); drawnow;
drawnow;
end
template_sim (o,i-1) = hoc_distance ( hoc_dist_name, hoc1, hoc2, cof1, cof2 , q);
end
% plot (1:n-1 , template_sim(o,:),colors{1,o},'LineWidth',2);
% hold on
end
% hold off
%% Template Matching with Model Update
utemplate_sim = zeros(1,n-1);
for o = 1:obj_cnt
disp(['Obj' num2str(o) ' Updated Template Similarity Calculation.'] );
hoc2 = frame_obj{1,o}.hoc; % template
cof2 = frame_obj{1,o}.rat; % template
for i = 2:n
hoc1 = frame_obj{i,o}.hoc; % this frame
cof1 = frame_obj{i,o}.rat;
hoc2 = template_update ( hoc_update , hoc2 , hoc1 , i );
% visualization of hoc differences
if (option_verbose)
subplot (3,3,[1,2]); hist_vis (hoc1,ctrs);
subplot (3,3,[4,5]); hist_vis (hoc2,ctrs);
subplot (3,3,3); imshow(frame_obj{i,o}.img);
subplot (3,3,[7,8]); bar (abs(hoc1-hoc2)); xlim([0 length(hoc1)]); ylim([0 0.2]); drawnow;
drawnow;
end
utemplate_sim (o,i-1) = hoc_distance ( hoc_dist_name, hoc1, hoc2 , cof1 , cof2 , q);
end
% plot (1:n-1 , intra_sim(o,:),colors{1,o},'LineWidth',2);
% hold on
end
% hold off
%% Normalization Phase
max_dist = max([intra_sim(:); inter_sim(:); template_sim(:); utemplate_sim(:)]);
big1 = ones(size(intra_sim));
big2 = ones(size(inter_sim));
intra_sim = big1 - intra_sim / max_dist;
inter_sim = big2 - inter_sim / max_dist;
template_sim = big1 - template_sim / max_dist;
utemplate_sim = big1 - utemplate_sim / max_dist;
o1o2 = squeeze(inter_sim(1,2,:));
o2o3 = squeeze(inter_sim(2,3,:));
o1o3 = squeeze(inter_sim(1,3,:));
%% Results
figure ('Name','Intra Similarity');
clf
pl= plot (1:n-1 ,intra_sim(1,:) ,'r-',1:n-1 , intra_sim(2,:), 'g-',1:n-1 , intra_sim(3,:),'b-');
set(pl,'LineWidth',2);
legend ('obj1','obj2','obj3','Location', 'SouthEast');
xlim([1 n]);
ylim([0 1]);
drawnow;
figure ('Name','Inter Similarity');
clf
pl= plot (1:n ,o1o2 ,'k-',1:n , o2o3, 'c-',1:n , o1o3,'m-');
set(pl,'LineWidth',2);
legend ('obj1-obj2','obj2-obj3','obj1-obj3','Location', 'SouthEast');
xlim([1 n+1]);
ylim([0 1]);
drawnow;
% figure ('Name','Template Matching');
% clf
% pl= plot (1:n-1 ,template_sim(1,:) ,'r-',1:n-1 , template_sim(2,:), 'g-',1:n-1 , template_sim(3,:),'b-');
% set(pl,'LineWidth',2);
% legend ('obj1','obj2','obj3','Location', 'SouthWest');
% xlim([1 n]);
% ylim([0.9 1]);
% drawnow;
% figure ('Name','Template Matching with Update');
% clf
% pl= plot (1:n-1 ,utemplate_sim(1,:) ,'r-',1:n-1 , utemplate_sim(2,:), 'g-',1:n-1 , utemplate_sim(3,:),'b-');
% set(pl,'LineWidth',2);
% legend ('obj1','obj2','obj3','Location', 'SouthWest');
% xlim([1 n]);
% ylim([0.9 1]);
% drawnow;
s1 = (sum(intra_sim')/n) * 100;
s2 = [sum(inter_sim(1,2,:)) sum(inter_sim(1,3,:)) sum(inter_sim(2,3,:))]/(n-1)*100;
s3 = sum(template_sim')/n*100;
s4 = sum(utemplate_sim')/n*100;
disp(' ');
disp(['Intra ' mat2str(s1)]);
disp(['Inter ' mat2str(s2)]);
disp(['Template ' mat2str(s3)]);
disp(['Template(U) ' mat2str(s4)]);
%% Total Results
s5(1) = mean(intra_sim(:)) * 100; s5(2) = var(intra_sim(:)) * 100;
s6(1) = mean(s2); s6(2) = var( [squeeze(inter_sim(1,2,:)) ; squeeze(inter_sim(1,3,:)) ; squeeze(inter_sim(2,3,:))])*100;
s7(1) = mean(s3); s7(2) = var(template_sim(:))*100;
s8(1) = mean(s4); s8(2) = var(utemplate_sim(:))*100;
disp(' ');
disp(['Total (mean/var) Intra ' mat2str(s5)]);
disp(['Total (mean/var) Inter ' mat2str(s6)]);
disp(['Total (mean/var) Template ' mat2str(s7)]);
disp(['Total (mean/var) Template(U) ' mat2str(s8)]);
s9 = sqrt(s5(1) * (100-s6(1)));
disp(['Score of This Combination sqrt(intra*(1-inter)): ' num2str(s9)]);