Content based image classification with the bag of visual words model in Python

Even with ever growing interest in deep learning I still find myself using the bag of visual word approach, if only to have a familiar baseline to test my new fancy algorithms against. I especially like the BoW demo script from the VLFeat team, that reaches a solid 65% accuracy on the, admittedly outdated, Caltech101 dataset. The script has the advantage that it is contains all the usual steps in one script (feature extraction, training of the classifier and evaluation of the whole pipeline) and that it can also be easily adapted to other datasets.

The only problem was, that it is a Matlab script and Matlab licences are in my experience often scarce due to their high price even for research institutes. So I rewrote the script in Python using the uncomplete VLFeat Python wrapper.

You can find my code as usual on github:

In case you are just diving into the world of BoW I recommend my minimal BoW image classifier code, which might be easier to understand.

How to create good and fast Matlab code

As most of the readers of this blog land on one of the pages with the Matlab applications, I thought I collect some of my resources I use to write Matlab code.

First start with the official Mathworks help on how to write good code

than we have this 33-page tutorial “Writing Fast MATLAB Code” (PDF)

followed by the Recorded Webinar: Handling Large Data Sets Efficiently in MATLAB

For asking questions, I enjoy the Stackoverflow community. Here are two examples of answers you get for generall Matlab questions.

So, I hope you find these links more helpful than overwhelming.

Please leave a comment if you have anything to add!

Seam carving tutorial for Matlab

I just found a Matlab tutorial at for content aware image scaling, aka seam carving. It is basically the same algorithms they use in PhotoShop CS4 for their ‘Content Aware Scaling’.

If you’ve never heard of seam carving make sure to watch the video

And here is an outlook into the future, a video demo what CS5 is able to do. Sweet magic.


for more on Matlab look at my post: Programming in Matlab!

Panoramic Photograph Stitching with Matlab

If you got access to an Matlab installation, you can also try to stitch a panorama yourself. At  Cris’s Image Analysis Blog I found a nice tutorial to do just that.  For two steps he is using his DIPimage toolbox, but you can also use Matlab’s Image Processing Toolbox.





for more on Matlab look at my post:How to create good and fast Matlab code


corrected links