-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample_script.m
327 lines (289 loc) · 9.82 KB
/
sample_script.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
function sample_script
disp('please see the comments inside the code');
% INSERT THE DESCRIPTOR NAME HERE
descriptor_name=[];
if isempty(descriptor_name)
error('descriptor_name is not set!');
end
mkdir(descriptor_name);
disp(['- descriptor_name is ''' descriptor_name '''']);
% create a temporary folder
tmp_data='tmp';
mkdir(tmp_data);
% DESCRIPTOR FUNCTION HANDLE - MUST BE REPLACED BY YOURS
% FIRST ARGUMENT MUST BE THE INPUT PATCH SET CSV FILE
% SECOND ARGUMENT MUST BE THE OUTPUT DESCRIPTOR SET CSV FILE
descriptor_function=[];
if ~isa(descriptor_function,'function_handle')
error('descriptor_function is not set!');
end
% suffix for patch orientation csv file to be applied
% CAN BE REPLACED WITH A CUSTOM ONE (SEE BELOW)
ori_suffix='ori';
if strcmp(ori_suffix,'ori')
disp(['- ori_suffix is ''' ori_suffix ''' - using default patch orientations, you can change this value with a custom one']);
end
% DESCRIPTOR MATCHING DISTANCE - CAN BE REPLACED BY A CUSTOM ONE
descriptor_matching_distance='euclidean';
disp(['- descriptor matching distance is ''' descriptor_matching_distance ''', you can change this value with a custom one']);
% directory containing downloaded patch sets
% CSV FILES OF PATCHES MUST BE EXTRACTED FROM THE 7ZIP ARCHIVES AND PUT IN
% THIS FOLDER - THERE ARE 27 ARCHIVES
in_folder='input_data';
if exist(in_folder,'dir')~=7
error('in_folder does not exist!');
end
disp(['- input data folder is ''' in_folder ''', please extract here the contest dataset']);
% pairs of patch sets to be matched
pairs={...
'graf1', 'graf2';...
'graf1', 'graf3';...
'graf1', 'graf4';...
'graf1', 'graf5';...
'graf1', 'graf6';...
'boat1', 'boat2';...
'boat1', 'boat3';...
'boat1', 'boat4';...
'boat1', 'boat5';...
'boat1', 'boat6';...
'bark1', 'bark2';...
'bark1', 'bark3';...
'bark1', 'bark4';...
'bark1', 'bark5';...
'bark1', 'bark6';...
'chatnoir1','chatnoir2';...
'chatnoir1','chatnoir3';...
'chatnoir1','chatnoir4';...
'chatnoir1','chatnoir5';...
'chatnoir1','chatnoir6';...
'DD1', 'DD2';...
'DD1', 'DD3';...
'DD1', 'DD4';...
'DD1', 'DD5';...
'DD1', 'DD6';...
'duckhunt1','duckhunt2';...
'duckhunt1','duckhunt3';...
'duckhunt1','duckhunt4';...
'duckhunt1','duckhunt5';...
'duckhunt1','duckhunt6';...
'floor1', 'floor2';...
'floor1', 'floor3';...
'floor1', 'floor4';...
'floor1', 'floor5';...
'floor1', 'floor6';...
'mario1', 'mario2';...
'mario1', 'mario3';...
'mario1', 'mario4';...
'mario1', 'mario5';...
'mario1', 'mario6';...
'marilyn1', 'marilyn2';...
'marilyn1', 'marilyn3';...
'marilyn1', 'marilyn4';...
'marilyn1', 'marilyn5';...
'marilyn1', 'marilyn6';...
'op1', 'op2';...
'op1', 'op3';...
'op1', 'op4';...
'op1', 'op5';...
'op1', 'op6';...
'outside1', 'outside2';...
'outside1', 'outside3';...
'outside1', 'outside4';...
'outside1', 'outside5';...
'outside1', 'outside6';...
'posters1', 'posters2';...
'posters1', 'posters3';...
'posters1', 'posters4';...
'posters1', 'posters5';...
'posters1', 'posters6';...
'screen1', 'screen2';...
'screen1', 'screen3';...
'screen1', 'screen4';...
'screen1', 'screen5';...
'screen1', 'screen6';...
'wall1', 'wall2';...
'wall1', 'wall3';...
'wall1', 'wall4';...
'wall1', 'wall5';...
'wall1', 'wall6';...
'spidey1', 'spidey2';...
'spidey1', 'spidey3';...
'spidey1', 'spidey4';...
'spidey1', 'spidey5';...
'spidey1', 'spidey6';...
'dc0', 'dc1';...
'dc0', 'dc2';...
'dc1', 'dc2';...
'castle0', 'castle1';...
'castle0', 'castle2';...
'castle1', 'castle2';...
'kermit0', 'kermit1';...
'kermit0', 'kermit2';...
'kermit1', 'kermit2';...
'sponge0', 'sponge1';...
'sponge0', 'sponge2';...
'sponge1', 'sponge2';...
'shelf0', 'shelf1';...
'shelf0', 'shelf2';...
'shelf1', 'shelf2';...
'tribal0', 'tribal1';...
'tribal0', 'tribal2';...
'tribal1', 'tribal2';...
'teddy0', 'teddy1';...
'teddy0', 'teddy2';...
'teddy1', 'teddy2';...
'pen0', 'pen1';...
'pen0', 'pen2';...
'pen1', 'pen2';...
'et0', 'et1';...
'et0', 'et2';...
'et1', 'et2';...
'desk0', 'desk1';...
'desk0', 'desk2';...
'desk1', 'desk2';...
'corridor0','corridor1';...
'corridor0','corridor2';...
'corridor1','corridor2';...
'dtua0', 'dtua1';...
'dtua0', 'dtua2';...
'dtua1', 'dtua2';...
'dtub0', 'dtub1';...
'dtub0', 'dtub2';...
'dtub1', 'dtub2';...
'dtuc0', 'dtuc1';...
'dtuc0', 'dtuc2';...
'dtuc1', 'dtuc2';...
'dtud0', 'dtud1';...
'dtud0', 'dtud2';...
'dtud1', 'dtud2';...
'dtuf0', 'dtuf1';...
'dtuf0', 'dtuf2';...
'dtuf1', 'dtuf2';...
'dtug0', 'dtug1';...
'dtug0', 'dtug2';...
'dtug1', 'dtug2';...
'fountain0','fountain1';...
'fountain0','fountain2';...
'fountain1','fountain2';...
'herzjesu0','herzjesu1';...
'herzjesu0','herzjesu2';...
'herzjesu1','herzjesu2';...
'build0', 'build1';...
'cart0', 'cart1';...
'church0', 'church1';...
'dante0', 'dante1';...
'facade0', 'facade1';...
'frame0', 'frame1';...
'groupsac0','groupsac1';...
'horse0', 'horse1';...
'plant0', 'plant1';...
'rooster0', 'rooster1';...
'scale0', 'scale1';...
'webcam0', 'webcam1';...
'standing0','standing1';...
'statue0', 'statue1';...
'valbonne0','valbonne1';...
'valencia0','valencia1';...
};
done_list={};
for i=1:size(pairs,1)
p1=pairs{i,1};
p2=pairs{i,2};
disp([num2str(i) '/' num2str(size(pairs,1)) ' - ' p1 ' - ' p2]);
bp1=[in_folder filesep p1 '_big_patches.csv'];
bp2=[in_folder filesep p2 '_big_patches.csv'];
op1=[in_folder filesep p1 '_' ori_suffix '.csv'];
op2=[in_folder filesep p2 '_' ori_suffix '.csv'];
if exist(bp1,'file')~=2 || exist(bp2,'file')~=2 || exist(op1,'file')~=2 || exist(op2,'file')~=2
error(['dataset is incomplete! please download and extract the required archives in the folder ''' in_folder '''']);
end
wp1=[tmp_data filesep p1 '_patches.csv'];
wp2=[tmp_data filesep p2 '_patches.csv'];
dp1=[tmp_data filesep p1 '_' descriptor_name '.csv'];
dp2=[tmp_data filesep p2 '_' descriptor_name '.csv'];
m12=[tmp_data filesep p1 '_' p2 '_' descriptor_name '_matches.csv'];
p12=[descriptor_name filesep p1 '_' p2 '_' descriptor_name '_snnr.csv'];
if ~any(strcmp(done_list,p1))
% rotate and crop the patches
rotate_and_crop_patch(bp1,op1,wp1);
% compute the descriptors
descriptor_function(wp1,dp1);
done_list=[done_list p1];
end
if ~any(strcmp(done_list,p2))
% rotate and crop the patches
rotate_and_crop_patch(bp2,op2,wp2);
% compute the descriptors
descriptor_function(wp2,dp2);
done_list=[done_list p2];
end
% compute the distance table
get_pairwise_matches(dp1,dp2,descriptor_matching_distance,m12);
% get the final matches
snnr_matches(m12,p12);
end
disp('*** DONE!!! ***');
zip([descriptor_name '.zip'],descriptor_name);
s=['sent the file ''' descriptor_name '.zip'' by email to wisw.caip2019@gmail.com'];
disp(s);
disp(repmat('=',[1 length(s)]));
disp('indicate in the email:');
disp('(1) participants'''' names, affiliations, and contact information');
disp('(2) the orientation estimation method employed for rotating the patches,');
disp('(3) the local image descriptor used (a brief explanation if unpublished or a reference)');
disp('(4) the distance employed for computing the distance table');
function rotate_and_crop_patch(big_patches_filename,patch_orientations_filename,oriented_patches_filename)
rad=48;
v=round(rad*sqrt(2))*2+1;
aux=zeros(v,v);
rb=(v-1)/2+1;
aux(rb-rad:rb+rad,rb-rad:rb+rad)=1;
aux=find(aux>0);
m=uint8(csvread(big_patches_filename));
o=csvread(patch_orientations_filename);
for i=1:size(m,1)
tmp=imrotate(reshape(m(i,:),[v v]),o(i),'bilinear','crop');
tmp=tmp';
m(i,:)=tmp(:);
end
csvwrite(oriented_patches_filename,m(:,aux));
function get_pairwise_matches(image_1_descriptor_filename,image_2_descriptor_filename,distance_metric,match_matrix_filename)
f1=single(csvread(image_1_descriptor_filename));
f2=single(csvread(image_2_descriptor_filename));
m=single(pdist2(f1,f2,distance_metric));
csvwrite(match_matrix_filename,m);
function snnr_matches(match_matrix_filename,snnr_matches_filename)
m=single(csvread(match_matrix_filename));
r=zeros(size(m,1),1);
c=zeros(1,size(m,2));
l=min(size(m,1),size(m,2));
p=zeros(l,3);
[~,idx]=sort(m(:));
[i,j]=ind2sub(size(m),idx);
kc=1;
for k=1:length(idx)
if ~r(i(k)) && ~c(j(k))
r(i(k))=1;
c(j(k))=1;
p(kc,1:2)=[i(k) j(k)];
kc=kc+1;
end
if kc>l
break;
end
end
for k=1:l
v=m(p(k,1),p(k,2));
aux_r=m(p(k,1),:);
aux_r(aux_r<v)=inf;
aux_r(p(k,2))=inf;
vr=min(aux_r);
aux_c=m(:,p(k,2));
aux_c(aux_c<v)=inf;
aux_c(p(k,1))=inf;
vc=min(aux_c);
p(k,3)=-(vr+vc)/(2*v);
end
[~,vdx]=sort(p(:,3));
p=p(vdx,:);
csvwrite(snnr_matches_filename,p);