given that you already have the "dictionary" from vl_kmeans:
[centers] = vl_kmeans(data, numClusters);
In order to build histogram of image I, you need to get the 128-D descriptors of that image using vl_sift:
[~,D] = vl_sift(I)
Each column of D is the descriptor of one interest point (or frame) in image I. Now you need to build the histogram of I based on D
and the dictionary centers
. The simplest way is using a for loop:
H = zeros(1,numClusters);
for i=1:size(D,2)
[~, k] = min(vl_alldist(D(:,i), centers)) ;
H(k) = H(k) + 1;
end
Now it is up to you to normalise the histogram H or not, before passing it to SVM. Note that there is possibly a faster way to build the histogram that does not need a loop; but I think my code (in Matlab) is clear enough to explain the algorithm.