How to get the variance of a binaryFeature object?

1 view (last 30 days)
I'm trying to write a program for object recognition using the bagOfFeatures approach described in Matlab. I want to create a custom extractor since I'm getting low accuracy with the default one. From the description, the function "extractFeatures" returns either a M by N matrix OR a binaryFeature object. I believe that the provided code in "exampleBagOfFeaturesExtractor.m" gets the variance assuming a M by N matrix is returned as follows:
multiscaleSURFPoints = detectSURFFeatures(grayImage);
features = extractFeatures(grayImage, multiscaleSURFPoints, 'Upright', true);
featureMetrix = var(features, [], 2);
When I change the type of feature detector to detectHarrisFeatures or detectBRISKFeatures I get the following error in var:
Undefined function 'sum' for input arguments of type 'binaryFeatures'.
This would suggest that a binaryFeature object was returned by extractFeatures instead of the matrix. From the documentation a binaryFeature object has a property 'Features' which is an M by N matrix, so I tried doing:
featureMetrix = var(features.Features, [], 2);
but this only generates more errors, telling me that the first argument must be single or double.

Answers (1)

Birju Patel
Birju Patel on 14 May 2015
Hi David,
The error is due to the use of binaryFeatures in your custom extractor. bagOfFeatures does not support binaryFeatures as a custom feature type. This is the cause of the error you see at the end: "the first output must be double or single".
The reason you are getting binaryFeatures from extractFeatures is because the detected points are cornerPoints (the output of either detectHarrisFeatures or detectBRISKFeatures). By default, extractFeatures returns binaryFeatures whenever it gets cornerPoint inputs.
You can change this behavior by setting extractFeatures 'Method' parameter to 'SURF'. That way, when you pass in the points detected by either the Harris or BRISK detectors, the extracted features will be SURF features. SURF features are stored as a matrix, so these can be used within your custom extractor.
You can get more info on the 'Method' parameter here:
HTH, Birju

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!