www.gusucode.com > vision 源码程序 matlab案例代码 > vision/CreateABagOfVisualWordsExample.m

    %% Create a Bag of Visual Words
%% 
% Load two image sets.
setDir  = fullfile(toolboxdir('vision'),'visiondata','imageSets');
imgSets = imageSet(setDir,'recursive');
%% 
% Pick the first two images from each image set to create training sets.
trainingSets = partition(imgSets,2);
%% 
% Create the bag of features. This process can take a few minutes.
bag = bagOfFeatures(trainingSets,'Verbose',false);
%% 
% Compute histogram of visual word occurrences for one of the images. 
% Store the histogram as feature vector.
img = read(imgSets(1),1);
featureVector = encode(bag,img);