encode

Create histogram of visual word occurrences

Description

example

featureVector = encode(bag,I) returns a feature vector that represents a histogram of visual word occurrences contained in the input image, I. The input bag contains the bagOfFeatures object.

[featureVector,words] = encode(bag,I) optionally returns the visual words as a visualWords object. The visualWords object stores the visual words that occur in I and stores the locations of those words.

featureVector= encode(bag,imds) returns a feature vector that represents a histogram of visual word occurrences contained in imds. The input bag contains the bagOfFeatures object.

[featureVector,words] = encode(bag,imds) optionally returns an array of visualWords occurrences in imds. The visualWords object stores the visual words that occur in I and stores the locations of those words.

[___] = encode(___,Name,Value) sets properties using one or more name-value pairs. Enclose each property name in quotes. For example, encode('SparseOutput',false)

This method supports parallel computing using multiple MATLAB® workers. Enable parallel computing from the Computer Vision Toolbox Preferences dialog box. To open Computer Vision Toolbox™ preferences, on the Home tab, in the Environment section, click Preferences. Then select Computer Vision Toolbox .

Examples

collapse all

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);
Creating Bag-Of-Features.
-------------------------
* Image category 1: books
* Image category 2: cups
* Selecting feature point locations using the Grid method.
* Extracting SURF features from the selected feature point locations.
** The GridStep is [8 8] and the BlockWidth is [32 64 96 128].

* Extracting features from 4 images...done. Extracted 76800 features.

* Keeping 80 percent of the strongest features from each category.

* Using K-Means clustering to create a 500 word visual vocabulary.
* Number of features          : 61440
* Number of clusters (K)      : 500

* Initializing cluster centers...100.00%.
* Clustering...completed 21/100 iterations (~0.73 seconds/iteration)...converged in 21 iterations.

* Finished creating Bag-Of-Features

Encode one of the images into a feature vector.

img = readimage(trainingSet,1);
featureVector = encode(bag,img);

Input Arguments

collapse all

Bag of features, specified as a bagOfFeatures object.

Input image, I, specified as a grayscale or truecolor image.

Images, specified as an ImageDatastore object.

Name-Value Pair Arguments

Example: 'SparseOutput',false

Type of normalization applied to the feature vector, specified as the comma-separated pair consisting of 'Normalization' and either 'L2' or 'none'.

Output sparsity, specified as the comma-separated pair consisting of 'SparseOutput' and as true or false. Set this property to true to return the visual word histograms in a sparse matrix. Setting this property to true reduces memory consumption for large visual vocabularies where the visual word histograms contain many zero elements.

Enable progress display to screen, specified as the comma-separated pair consisting of 'Verbose' and the logical true or false.

Output Arguments

collapse all

Histogram of visual word occurrences, specified as M-by-bag.VocabularySize vector, where M is the total number of images in imds, numel(imds.Files).

Visual words object, returned as a visual words object or an array of visual words objects. The visualWords object stores the visual words that occur in the images and stores the locations of those words.

Extended Capabilities

Introduced in R2014b