Documentation - C API
Vector of Locally Aggregated Descriptors (VLAD) encoding
Author:
David Novotny
Andrea Vedaldi

vlad.h implements the Vector of Linearly Aggregated Descriptors (VLAD) image representation [9] [2] .

Getting started with VLAD demonstreates how to use the C API to compute the VLAD representation of an image. For further details on the VLAD image representation refer to:

Getting started with VLAD

The VLAD encoding of a set of features is obtained by using the function vl_vlad_encode. The function can be applied to both float or double data types.

vl_vlad_encode requires a visual dictionary, for example obtained by using K-means clustering. Furthermore, the assignments of features to dictionary elements must be pre-computed, for example by using KD-trees and forests.

In the following example code, the vocabulary is first created using the KMeans clustering, then the points, that are to be encoded are assigned to its corresponding nearest vocabulary words, after that the original vlad encoding routine without any normalization option takes place. At the end of the process the encoding is stored in the enc variable.

vl_uint32 * indexes;
float * assignments;
float * enc
int i;
// create a KMeans object and run clustering to get vocabulary words (centers)
kmeans = vl_kmeans_new (VLDistanceL2, VL_TYPE_FLOAT) ;
data,
dimension,
numData,
numCenters) ;
// find nearest cliuster centers for the data that should be encoded
indexes = vl_malloc(sizeof(vl_uint32) * numDataToEncode);
vl_kmeans_quantize(kmeans,indexes,dataToEncode,numDataToEncode);
// convert indexes array to assignments array,
// which can be processed by vl_vlad_encode
assignments = vl_malloc(sizeof(float) * numDataToEncode * numCenters);
memset(assignments, 0, sizeof(float) * numDataToEncode * numCenters);
for(i = 0; i < numDataToEncode; i++) {
assignments[i + numDataToEncode * indexes[i]] = 1.;
}
// allocate space for vlad encoding
enc = vl_malloc(sizeof(TYPE) * dimension * numCenters);
// do the encoding job
vl_vlad_encode (enc, VL_F_TYPE,
vl_kmeans_get_centers(kmeans), dimension, numCenters,
data, numData,
assignments,
0) ;

Various VLAD normalization normalizations can be applied to the VLAD vectors. These are controlled by the parameter flag of vl_vlad_encode.