Bag-of-Words (BOW) in VLFeat

自古美人都是妖i 提交于 2019-12-04 22:17:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!