-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_features_sift.m
52 lines (47 loc) · 1.86 KB
/
test_features_sift.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
function [image_features] = test_features_sift(vocabulary)
%Step size for SIFT detection
step_size=4;
vocab_size = size(vocabulary, 1);
%positives_test_dataset
%test_data2
plane_source = 'D:\Mandeep\Summer\BTP\Tracking\Hog\negatives_test_data\';
files = dir('D:\Mandeep\Summer\BTP\Tracking\Hog\negatives_test_data\*.jpg');
count = length(files);
total_images = count;
counter = 1;
image_counter = 1;
fprintf('Computing Bag of words\n');
while(image_counter <= total_images)
filename = strcat(plane_source,num2str(counter),'.jpg');
if exist(filename,'file')
if (mod(image_counter,100)==0)
fprintf(' ..Processed %d Images\n',image_counter);
%fprintf(' Size of hog features : \n');
%size(hog_features)
end
try
img = im2single(rgb2gray(imread(filename)));
catch
fprintf('Probelm in file %d',counter);
counter = counter + 1;
continue
end
%gives 128 x num_of_features with one descriptor per column
%hog = vl_hog(img,step_size);
%[x,y,z] = size(hog);
%hog_features = (reshape(hog,[x*y,z]))';
%to reduce precision to 32
[~, features] = vl_dsift(img, 'Fast', 'Step', step_size);
features = single(features);
[indices, distances] = knnsearch(vocabulary, features');
%generating histogram and then normalizing it
imhist=histc(indices, 1:vocab_size);
imhist_norm=imhist./numel(imhist);
image_features(image_counter,:) = imhist_norm';
image_counter = image_counter + 1;
counter = counter + 1;
else
counter = counter + 1;
end
end
end