I am using bag of features to classify histology images in MATLAB.
here is the code that I used. It's taken from the `imageCategoryClassificationExample
Location of the compressed data set
url=http://www.vision.caltech.edu/Image_Datasets/Caltech101/101_ObjectCategories.tar.gz';
Store the output in a temporary folder
outputFolder = fullfile(tempdir, 'caltech101');
rootFolder = fullfile(outputFolder, '101_ObjectCategories');
imgSets = [ imageSet(fullfile(rootFolder, 'airplanes')), ...
imageSet(fullfile(rootFolder, 'ferry')), ...
imageSet(fullfile(rootFolder, 'laptop')) ];
determine the smallest amount of images in a category
minSetCount = min([imgSets.Count]);
Use partition
method to trim the set.
imgSets = partition(imgSets, minSetCount, 'randomize');
Separate the sets into training and validation data.
[trainingSets, validationSets] = partition(imgSets, 0.3, 'randomize');
Create the bag of features classifier
bag = bagOfFeatures(trainingSets);
Additionally, the bagOfFeatures
object provides an encode
method for
counting the visual word occurrences in an image. It produced a histogram
that becomes a new and reduced representation of an image.
img = read(imgSets(1), 1);
[featureVector,words] = encode(bag, img);
Plot the histogram of visual word occurrences
figure
bar(featureVector)
title('Visual word occurrences')
xlabel('Visual word index')
ylabel('Frequency of occurrence')
After the creation of the bag of features object how can I visualize the final codebook and which visual words make up each image? Can I reconstruct the image from these words? I think it has to do with the use of encode
to create a visualWords
object. But how do I proceed after that?