I'm building a project Images Classification with Bag-of-Visual-Words (BoVW) using VLFeat library. The BoVW pipeline includes:
我正在使用VLFeat库构建一个项目图像分类,其中包含了visualword (BoVW)。BoVW管道包括:
- SIFT
- 筛选
- k-means
- k - means
- Building histogram
- 建立柱状图
- 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)和(2)使用vl_sift和vl_kmeans,但是我不知道如何构建直方图特性并在SVM中使用它们。
1 个解决方案
#1
0
given that you already have the "dictionary" from vl_kmeans:
既然你已经有了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:
为了构建image I的直方图,您需要使用vl_sift来获取该图像的128-D描述符:
[~,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:
D的每一列都是图像I中一个兴趣点(或帧)的描述符。现在需要基于D和字典中心构建I的直方图。最简单的方法是使用for循环:
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.
现在,在将直方图传递给SVM之前,是否将其正常化取决于您。注意,可能有一种更快的方法来构建不需要循环的直方图;但是我认为我的代码(在Matlab中)足够清晰,可以解释这个算法。
#1
0
given that you already have the "dictionary" from vl_kmeans:
既然你已经有了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:
为了构建image I的直方图,您需要使用vl_sift来获取该图像的128-D描述符:
[~,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:
D的每一列都是图像I中一个兴趣点(或帧)的描述符。现在需要基于D和字典中心构建I的直方图。最简单的方法是使用for循环:
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.
现在,在将直方图传递给SVM之前,是否将其正常化取决于您。注意,可能有一种更快的方法来构建不需要循环的直方图;但是我认为我的代码(在Matlab中)足够清晰,可以解释这个算法。