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

    %% Encode an Image into a Feature Vector
%
%% 
% Load a set of image.
setDir  = fullfile(toolboxdir('vision'),'visiondata','imageSets');
imds = imageDatastore(setDir,'IncludeSubfolders',true,'LabelSource',...
    'foldernames');
%% 
% Pick the first two images from each label.
trainingSet = splitEachLabel(imds,2);
%% 
% Create bag of features.
bag = bagOfFeatures(trainingSet);
%% 
% Encode one of the images into a feature vector.
img = readimage(trainingSet,1);
featureVector = encode(bag,img);