File Exchange

image thumbnail

compute bag of visual word representation for an image

version 1.1 (6.31 KB) by

computes BOV/BOF/BOW representation for an image. Codebook and image features are user inputs.

4 Ratings



View License

If you have the codebook with you, you can represent an image as a bag of (visual) words, using this function. This gives the histogram of the codebook entries (called codewords), in the extracted features of th eimage. You need to pass the extracted features from the image also as input to the function. This function can work with any type of features. One important note is, you MUST have a working version of 'yael' library of INRIA on your machine. The output histogram can be normalized (third argument).

Comments and Ratings (13)

Overall, this is pretty useful! Thanks!

As feedback:

It contains a logical bug in the file computeBoV.m
There is an if block as follows:
if(Nind~=0 || Nind~=1)
This would always evaluate to true (and fail the execution)!
There may be a few more minor inconsistencies.

Secondly, the feature vectors are represented as columns which differs from what MATLAB's internal functions use i.e. each row is a feature vector.

Anyway, it is wonderful that this code was shared over MATLAB central.


how to generate a codebook

can I use your code for creating a bag of visual words from a SURF feature extracted by 'extractedSURFFeatures' in MATLAB? Actually it creates a multi dimensional feature. and if we use 'extractFeatures' on the out put of the 'extractedSURFFeatures' we can convert in to a matrix.. I want to train the neural network with this feature vector. for that I need a single line vector. can i do it with this?

sapna sapna

i want to use sift features for human action recognition. i have multiple human in a single frame.SIFT extracted from each frame is kx128 to create bag of visual words from these features??

@Lakshmi: I don't know why you get a 2D matrix as SIFT feature, in general it should be a single 128D vector at each keypoint. But, even if you get a 2D matrix as your feature, you may go ahead after column stacking it.


I want to generate BoVW from sift feature. I'm getting a 2d matrix as SIFT feature. Should i convert it into 1d for giving it as input to the BoVW?

Konda: Thanks very good code,could you make a test example for use it as demo (for image features extraction) where my master project on it ,and thanks in advance.

@hameed: BoW representation is widely used along with many of its improved variants for classification, retrieval kind of applications. You may get some overview here
thank you !!

Konda: thanks very good code,I am wondering how can I use your code for medical images classification like skin cancer(i.e. Melanoma),how can I do that?

Hi, you said that you obtained the Vwords as the output of kmeans algorithms, actually what is the input data given to the kmeans for clustering ?? that itself is the features. For example it can be the SIFT features extracted from an image.

@hamed: Welcome !!


asmae (view profile)

dear CONDA,
how to get 'feats' from the images 'jpg' <901x1201x3 uint8>? for Vwords I took the centroids <49x50 Double> obtained by Kmeans algorithm.

Thanks very good code



1. Provison soft assignment
2. Codebook learning via K-means are added

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video