-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppendGraphsL2.m
executable file
·80 lines (58 loc) · 2.4 KB
/
AppendGraphsL2.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
function Graph = AppendGraphsL2(suffix, IndexFile, NeibFile, ImIdxA, features_name, K, L)
%ImageDir = 'e:\MATLAB\im_parser\LabelMe\Images\';
DescriptorsDir = 'e:\MATLAB\im_parser\LabelMe\Data\Descriptors\SP_Desc_k200\';
GtDir = 'e:\MATLAB\im_parser\LabelMe\SemanticLabels\';
%file_list = dir(ImageDir);
%feature_names = cell(1);
%features_name = 'sift_hist_dial';
%features_name = 'dial_color_hist';
%features_name = 'dial_text_hist_mr';
load(IndexFile);
%load(['Graph_' features_name '_' num2str(K) '_' num2str(L) '_' suffix '.mat'], 'Graph', 'K', 'L');
load(NeibFile);
%
% ImIdx = 1:2:length(Index);
% idx = zeros(1,TotalSP);
%
% for i = ImIdx
% idx(Index{i}.offset+1:Index{i}.offset + Index{i}.tot_sp) = 1;
% end
Graph = sparse(TotalSP, TotalSP);
for image_i = ImIdxA %1 : length(Index)
curr_name = Index{image_i}.name;
load( [GtDir curr_name '.mat']);
%features = cell(size(feature_names));
features = load( [ DescriptorsDir features_name '\' curr_name '.mat']);
features = features.desc;
im_j_neib = zeros(size(features,2), TotalSP) + 10000;
for image_j = PerImageNeibs(image_i,:)
disp(['image_i = ' num2str(image_i) '; image_j = ' num2str(image_j)]);
if(image_i == image_j)
continue;
end
% if( isempty(intersect(Index{image_i}.labels, Index{image_j}.labels)) )
% continue;
% end
j_name = Index{image_j}.name;
load( [GtDir j_name '.mat']);
features_j = load( [ DescriptorsDir features_name '\' j_name '.mat']);
features_j = features_j.desc;
for i = 1 : size(features,2)
neibs = zeros(1, size(features_j,2));
for j = 1 : size(features_j,2)
loc_dist = features(:,i) - features_j(:,j);
neibs(j) = norm(loc_dist);
end
[val idx] = sort(neibs);
im_j_neib(i, idx(1:K) + Index{image_j}.offset) = val(1:K);
end
end
for i = 1 : size(features,2)
[val idx] = sort(im_j_neib(i,:));
%Graph(i + Index{image_i}.offset, :) = 0;
Graph(i + Index{image_i}.offset, idx(1:L)) = val(1:L);
end
end
Graph(Graph > 0) = 1 - Graph(Graph > 0);
Graph(Graph < 0) = 0;
save(['Graph_' features_name '_' num2str(K) '_' num2str(L) '_' suffix '_full.mat'], 'Graph', 'K', 'L')