Custom feature extractor is not recognized by bagOfFeatures function
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm trying to create a bag-of-visual-words model using my custom feature extractor function, but the BoW is always generated using SURF features. Below is a toy example to reproduce the problem:
clc; clear all; close all;
% Load images in the workspace
imageDir = fullfile(toolboxdir('vision'),'visiondata','structureFromMotion');
% Create an imageDataStore object
imds = imageDatastore(imageDir);
% Test the feature extractor
I = readimage(imds, 1);
[features, featureMetrics] = exampleExtractor(I);
% Create a virtual vocabulary with the custom feature descriptor
extractor = @exampleExtractor;
imageIndex = indexImages(imds);
bag = bagOfFeatures(imds, 'CustomExtractor', extractor, ...
'TreeProperties', [2, 10], 'StrongestFeatures', 1);
function [features, featureMetrics, varargout] = exampleExtractor(I)
% Convert image to grayscale, if necessary
[height, width, numChannels] = size(I);
if numChannels > 1
grayImage = rgb2gray(I);
else
grayImage = I;
end
% Define a regular grid over I
gridStep = 8;
gridX = 1:gridStep:width;
gridY = 1:gridStep:height;
[X,Y] = meshgrid(gridX, gridY);
gridLocations = [X(:), Y(:)];
% Multi-scale feature extraction
multiscaleGridPoints = [SIFTPoints(gridLocations, 'Scale', 1.6);
SIFTPoints(gridLocations, 'Scale', 3.2);
SIFTPoints(gridLocations, 'Scale', 4.8)];
features = extractFeatures(grayImage, multiscaleGridPoints, ...
'Upright', true, 'Method', 'SIFT');
% Compute the feature metric
featureMetrics = var(features, [], 2);
% Optinal output
if nargout > 2
varargout{1} = multiscaleGridPoints.Location;
end
end
Although the custom feature extractor uses the SIFT feature in this code, the BoW is created using the SURF features:
Creating an inverted image index using Bag-Of-Features.
-------------------------------------------------------
Creating Bag-Of-Features.
-------------------------
* Selecting feature point locations using the Detector method.
* Extracting SURF features from the selected feature point locations.
** detectSURFFeatures is used to detect key points for feature extraction.
Does anyone know where I'm doing wrong?
0 comentarios
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!