Remark. This code is obsolete. An analogous example, much improved and far simpler, is now part of our VLFeat library. This page is kept here for reference only.

Bag of features is a well established technique for the visual classification of objects, categories of objects and textures. This is an implementation of a simplified version of the method of [1], which is based on the concept of hierarchical K-means dictionary. This technique is appealing because of its simplicity and power. I also used suggestions from [2], namely the extraction of random features.

I tested the code on Caltech-4, which is known to be an easy dataset. Performances are indeed very good, especially considering that I did not spend time tuning parameters. More recently I have tried Clatech-101, getting good results considering the simplicity of the method.

I decided to post the code as it might turn useful for classess or experiments.

Download and install

The software of a couple of MATLAB M and MEX files and a few scripts for GNU/Make:

  • Bag. This contains the core programs (download the source code).
  • sift++. This is used to compute the SIFT features (download here).

The rest of the requirements are starndard:

Besides MATLAB, everything is free software and should come with every Linux distribution. On Mac OS X, most elements are installed with the developers tool, and, if you have TeX installed, convert is probably installed too (look in /usr/local/bin).

The code can be compilied by issuing

> make

This requires MATLAB MEX compiler to be in the command path. In some case it might be necessary to adjust the Makefile for this to work. In any case, compiling the code should be trivial enough even by hand.

To run the M and MEX file, add to MATLAB path both the main directory bag and the sub-directory bag/mex, which contains the compiled MEX files.

If everything is fine, issuing test_ikmeas should produce a picture like the following:

tree

Getting started

See the walkthorugh.

References