-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperform_vectorquantization.m
62 lines (41 loc) · 1.65 KB
/
perform_vectorquantization.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
function perform_vectorquantization
%function perform_vectorquantization(meanVec,stdVec)
%-------------------------------------------------------
%vector quantization on test images
load('temp/codebook.mat');
visualwords = size(centers,2);
testquality =[];
%%% Loop over all images....
for i= 1:982
% if (mod(i,10)==0)
% fprintf('.%d\n',i);
% end
%%% Load up interest point file
load(sprintf('temp/features_local%d.mat',i));
%feat = whitenTestingData(feat, meanVec, stdVec);
feat = feat';
%%% Find number of points per image
nPoints = size(feat,2);
%%% Set distance matrix to all be large values
%distance = Inf * ones(nPoints,visualwords);
% %%% Loop over all centers and all points and get L2 norm btw. the two.
% for p = 1:nPoints
% for c = 1:visualwords
% distance(p,c) = norm(centers(:,c) - double(feat(:,p)));
% end
% end
distance = sqrt(dist2(feat', centers'));
%%% Now find the closest center for each point
[tmp,descriptor_vq] = min(distance,[],2);
%%% Now compute histogram over codebook entries for image
histogram = zeros(1,visualwords);
for p = 1:nPoints
histogram(descriptor_vq(p)) = histogram(descriptor_vq(p)) + 1;
end
% new line of code added post SP letters draft
histogram = histogram./sum(histogram);
%%% transpose to match other variables
descriptor_vq = descriptor_vq';
%%% append descriptor_vq variable to file....
save(sprintf('temp/histogram_%d.mat',i),'histogram','descriptor_vq');
end