-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildGlobalDescriptors.m
executable file
·212 lines (155 loc) · 5.76 KB
/
BuildGlobalDescriptors.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
clear;
addpath D:\MATLAB\vlfeat-0.9.9\toolbox\ ;
addpath D:\MATLAB\phog\ ;
addpath D:\MATLAB\GIST\ ;
vl_setup();
in_dir = 'd:\MATLAB\im_parser\LabelMeDataSet\Images\';
suffix = 'Test';
load(['Index' suffix]);
ImagesDB = cell(1,length(Index));
k = 1;
for i = 1 : length(Index)
name = [Index{i}.name '.jpg'];
ImagesDB{k}.name = name;
ImagesDB{k}.labels = Index{i}.labels;
k = k + 1;
end
Nblocks = 4;
imageSize = 256;
orientationsPerScale = [8 8 4];
numberBlocks = 4;
% Precompute filter transfert functions (only need to do this one, unless image size is changes):
createGabor(orientationsPerScale, imageSize); % this shows the filters
G = createGabor(orientationsPerScale, imageSize);
GIST = zeros(500, 960);
%PHOG stuff
bin = 8;
angle = 360;
L=3;
load('PHOW_centers_color.mat');
load('PHOW_centers_gray.mat');
for i = 1 : length(ImagesDB)
i
%descr_idx = 1;
file_name = ImagesDB{i}.name;
img = imread([in_dir file_name]);
h = size(img,1);
w = size(img,2);
% full image PHOW, color
[frames, descr] = vl_phow(im2single(img), 'Color', true);
I = vl_ikmeanspush(descr,PHOW_centers_color);
total_H = vl_ikmeanshist(size(PHOW_centers_color,2),I);
ImagesDB{i}.Features{2} = sparse(total_H / sum(total_H));
% PHOW descriptor horyzontal, color
total_H = [];
for sub = 0 : 2
from = sub * floor(h/3) + 1;
to = (sub+1)*floor(h/3);
[frames, descr] = vl_phow(im2single(img(from:to,:,:)), 'Color', true);
I = vl_ikmeanspush(descr,PHOW_centers_color);
H = vl_ikmeanshist(size(PHOW_centers_color,2),I);
total_H = cat(1, total_H, H);
end
ImagesDB{i}.Features{3} = sparse(total_H / sum(total_H));
% PHOW descriptor quadtree, color
total_H = [];
for sub_x = 0 : 1
for sub_y = 0 : 1
from_x = sub_x * floor(h/2) + 1;
to_x = (sub_x+1)*floor(h/2);
from_y = sub_y * floor(w/2) + 1;
to_y = (sub_y+1)*floor(w/2);
[frames, descr] = vl_phow(im2single(img(from_x:to_x,from_y:to_y,:)), 'Color', true);
I = vl_ikmeanspush(descr,PHOW_centers_color);
H = vl_ikmeanshist(size(PHOW_centers_color,2),I);
total_H = cat(1, total_H, H);
end
end
ImagesDB{i}.Features{4} = sparse(total_H / sum(total_H));
total_H = [];
for sub_x = 0 : 3
for sub_y = 0 : 3
from_x = sub_x * floor(h/4) + 1;
to_x = (sub_x+1)*floor(h/4);
from_y = sub_y * floor(w/4) + 1;
to_y = (sub_y+1)*floor(w/4);
[frames, descr] = vl_phow(im2single(img(from_x:to_x,from_y:to_y,:)), 'Color', true);
I = vl_ikmeanspush(descr,PHOW_centers_color);
H = vl_ikmeanshist(size(PHOW_centers_color,2),I);
total_H = cat(1, total_H, H);
end
end
ImagesDB{i}.Features{5} = sparse(total_H / sum(total_H));
% full image PHOW, gray
[frames, descr] = vl_phow(im2single(img), 'Color', false);
I = vl_ikmeanspush(descr,PHOW_centers_gray);
total_H = vl_ikmeanshist(size(PHOW_centers_gray,2),I);
ImagesDB{i}.Features{6} = sparse(total_H / sum(total_H));
% PHOW descriptor horyzontal, gray
total_H = [];
for sub = 0 : 2
from = sub * floor(h/3) + 1;
to = (sub+1)*floor(h/3);
[frames, descr] = vl_phow(im2single(img(from:to,:,:)), 'Color', false);
I = vl_ikmeanspush(descr,PHOW_centers_gray);
H = vl_ikmeanshist(300,I);
total_H = cat(1, total_H, H);
end
ImagesDB{i}.Features{7} = sparse(total_H / sum(total_H));
% PHOW descriptor quadtree, gray
total_H = [];
for sub_x = 0 : 1
for sub_y = 0 : 1
from_x = sub_x * floor(h/2) + 1;
to_x = (sub_x+1)*floor(h/2);
from_y = sub_y * floor(w/2) + 1;
to_y = (sub_y+1)*floor(w/2);
[frames, descr] = vl_phow(im2single(img(from_x:to_x,from_y:to_y,:)), 'Color', false);
I = vl_ikmeanspush(descr,PHOW_centers_gray);
H = vl_ikmeanshist(300,I);
total_H = cat(1, total_H, H);
end
end
ImagesDB{i}.Features{8} = sparse(total_H / sum(total_H));
total_H = [];
for sub_x = 0 : 3
for sub_y = 0 : 3
from_x = sub_x * floor(h/4) + 1;
to_x = (sub_x+1)*floor(h/4);
from_y = sub_y * floor(w/4) + 1;
to_y = (sub_y+1)*floor(w/4);
[frames, descr] = vl_phow(im2single(img(from_x:to_x,from_y:to_y,:)), 'Color', false);
I = vl_ikmeanspush(descr,PHOW_centers_gray);
H = vl_ikmeanshist(size(PHOW_centers_gray,2),I);
total_H = cat(1, total_H, H);
end
end
ImagesDB{i}.Features{9} = sparse(total_H / sum(total_H));
%colors
%RGB
for c = 1:3
chanel = img(:,:,c);
chanel = chanel(:);
H = histc(chanel, 0:20:256);
total_H = cat(1, total_H, H);
end
ImagesDB{i}.Features{10} = sparse(total_H / sum(total_H));
%HSV
hsv_img = rgb2hsv(img);
for c = 1:3
chanel = hsv_img(:,:,c);
chanel = chanel(:);
H = histc(chanel, 0:0.1:1);
total_H = cat(1, total_H, H);
end
ImagesDB{i}.Features{11} = sparse(total_H / sum(total_H));
%PHOG
roi = [1;size(img,1);1;size(img,2)];
p = anna_phog(im2double(img),bin,angle,L,roi);
ImagesDB{i}.Features{12} = p;
img = imresize(img, [imageSize imageSize]);
output = prefilt(double(img), 4);
g = gistGabor(output, numberBlocks, G);
ImagesDB{i}.Features{1} = g;
end
save(['LabelMeGlobalFeat' suffix '.mat'], 'ImagesDB');