-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLC_pooling.m
66 lines (53 loc) · 1.67 KB
/
LLC_pooling.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
% ========================================================================
% Pooling the llc codes to form the image feature
% USAGE: [beta] = LLC_pooling(feaSet, B, pyramid, knn)
% Inputs
% feaSet -the coordinated local descriptors
% B -the codebook for llc coding
% pyramid -the spatial pyramid structure
% knn -the number of neighbors for llc coding
% Outputs
% beta -the output image feature
%
% Written by Jianchao Yang @ IFP UIUC
% May, 2010
% ========================================================================
function [beta] = LLC_pooling(feaSet, B, pyramid, knn)
dSize = size(B, 2);
nSmp = size(feaSet.feaArr, 2);
img_width = feaSet.width;
img_height = feaSet.height;
idxBin = zeros(nSmp, 1);
% llc coding
llc_codes = LLC_coding_appr(B', feaSet.feaArr', knn);
llc_codes = llc_codes';
% spatial levels
pLevels = length(pyramid);
% spatial bins on each level
pBins = pyramid.^2;
% total spatial bins
tBins = sum(pBins);
beta = zeros(dSize, tBins);
bId = 0;
for iter1 = 1:pLevels,
nBins = pBins(iter1);
wUnit = img_width / pyramid(iter1);
hUnit = img_height / pyramid(iter1);
% find to which spatial bin each local descriptor belongs
xBin = ceil(feaSet.x / wUnit);
yBin = ceil(feaSet.y / hUnit);
idxBin = (yBin - 1)*pyramid(iter1) + xBin;
for iter2 = 1:nBins,
bId = bId + 1;
sidxBin = find(idxBin == iter2);
if isempty(sidxBin),
continue;
end
beta(:, bId) = max(llc_codes(:, sidxBin), [], 2);
end
end
if bId ~= tBins,
error('Index number error!');
end
beta = beta(:);
beta = beta./sqrt(sum(beta.^2));