Bag-of-Words (BOW) in VLFeat

馋奶兔 提交于 2019-12-10 00:25:43

问题


I'm building a project Images Classification with Bag-of-Visual-Words (BoVW) using VLFeat library. The BoVW pipeline includes:

  1. SIFT
  2. k-means
  3. Building histogram
  4. SVM classification

I can use vl_sift and vl_kmeans for (1) and (2), but I don't know how to build histogram features and use them in SVM.


回答1:


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.



来源:https://stackoverflow.com/questions/23104750/bag-of-words-bow-in-vlfeat

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