Code covered by the BSD License  

Highlights from
compute bag of visual word representation for an image

compute bag of visual word representation for an image

by

 

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

BoWvec=computeBoV(Vwords,feats,Nind)
function BoWvec=computeBoV(Vwords,feats,Nind)
%% Computes the Bag of Visual word ( BoV/BoW/BoF ) representation of an image or video
%
% Inputs->
%
% Vwords: visual words or centroids or cluster centers (each column is a word)
% feats : features extracted from an entity (image/video)(each column is a feature)
% Nind  : Normalizatin index
%           0-no normalization
%           1-l1 noramlisation
%           2-l2 normalization
%
% ***************************  Needs INRIA's yael library ******************
% Output->
%
% BoWvec : output BoW vector (column Vector)
% 
% Author: Mopuri K Reddy, SERC, IISC Banglore, 24/7/13.

if(Nind>2)
    disp('please specify correct normalization from 0, 1, 2');
    return;
end
if(size(Vwords,1)~=size(feats,1))
    disp('please check the i/p arguments: sizes are not matching');
    return;
end

% addpath(genpath('path to yael library'));
% adds the 'yael' library here. ( If not added already, uncomment the above statement; If it is added already, no need to uncomment )

dis_type=2;
% you can specify the distance type here.

[idx dis]=yael_nn(single(Vwords),single(feats),1,dis_type);
BoWvec = hist( double(idx), 1:size(Vwords,2) );

if(Nind==1)
    BoWvec=BoWvec/sum(BoWvec);
    % BoW is a histogram, contains nonzero entries, so sum is same as absolute sum
else if(Nind==2)
        BoWvec=BoWvec/sqrt(sum(BoWvec.*BoWvec));
    end
end
BoWvec=BoWvec';

Contact us