Click or drag to resize
Accord.NET (logo)

SpeededUpRobustFeaturesDetector Class

Speeded-up Robust Features (SURF) detector.
Inheritance Hierarchy
SystemObject
  Accord.ImagingBaseFeatureExtractorSpeededUpRobustFeaturePoint
    Accord.ImagingBaseSparseFeatureExtractorSpeededUpRobustFeaturePoint
      Accord.ImagingSpeededUpRobustFeaturesDetector

Namespace:  Accord.Imaging
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class SpeededUpRobustFeaturesDetector : BaseSparseFeatureExtractor<SpeededUpRobustFeaturePoint>
Request Example View Source

The SpeededUpRobustFeaturesDetector type exposes the following members.

Constructors
  NameDescription
Public methodSpeededUpRobustFeaturesDetector
Initializes a new instance of the SpeededUpRobustFeaturesDetector class.
Top
Properties
  NameDescription
Public propertyComputeDescriptors
Gets or sets a value indicating whether all feature points should have their descriptors computed after being detected. Default is to compute standard descriptors.
Public propertyComputeOrientation
Gets or sets a value indicating whether all feature points should have their orientation computed after being detected. Default is true.
Public propertyNumberOfInputs
Returns -1.
(Inherited from BaseFeatureExtractorTFeature.)
Public propertyNumberOfOutputs
Gets the dimensionality of the features generated by this extractor.
(Inherited from BaseFeatureExtractorTFeature.)
Public propertyOctaves
Gets or sets the number of octaves to use when building the response filter. Each octave corresponds to a series of maps covering a doubling of scale in the image. Default is 5.
Public propertyStep
Gets or sets the initial step to use when building the response filter. Default is 2.
Public propertySupportedFormats
Gets the list of image pixel formats that are supported by this extractor. The extractor will check whether the pixel format of any provided images are in this list to determine whether the image can be processed or not.
(Inherited from BaseFeatureExtractorTFeature.)
Public propertyThreshold
Gets or sets the non-maximum suppression threshold. Default is 0.0002.
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Inherited from BaseFeatureExtractorTFeature.)
Protected methodClone(ISetPixelFormat)
Creates a new object that is a copy of the current instance.
(Overrides BaseFeatureExtractorTFeatureClone(ISetPixelFormat).)
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from BaseFeatureExtractorTFeature.)
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
(Overrides BaseFeatureExtractorTFeatureDispose(Boolean).)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetDescriptor
Gets the feature descriptor for the last processed image.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodInnerTransform
This method should be implemented by inheriting classes to implement the actual feature extraction, transforming the input image into a list of features.
(Overrides BaseFeatureExtractorTFeatureInnerTransform(UnmanagedImage).)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProcessImage(Bitmap) Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseSparseFeatureExtractorTPoint.)
Public methodProcessImage(BitmapData) Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseSparseFeatureExtractorTPoint.)
Public methodProcessImage(UnmanagedImage) Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseSparseFeatureExtractorTPoint.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransform(Bitmap)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.)
Public methodTransform(Bitmap)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.)
Public methodTransform(UnmanagedImage)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.)
Public methodTransform(UnmanagedImage)
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.)
Public methodTransform(Bitmap, IEnumerableTFeature)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from BaseFeatureExtractorTFeature.)
Public methodTransform(UnmanagedImage, IEnumerableTFeature)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from BaseFeatureExtractorTFeature.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

Based on original implementation in the OpenSURF computer vision library by Christopher Evans (http://www.chrisevansdev.com). Used under the LGPL with permission of the original author.

Be aware that the SURF algorithm is a patented algorithm by Anael Orlinski. If you plan to use it in a commercial application, you may have to acquire a license from the patent holder.

References:

  • E. Christopher. Notes on the OpenSURF Library. Available in: http://sites.google.com/site/chrisevansdev/files/opensurf.pdf
  • P. D. Kovesi. MATLAB and Octave Functions for Computer Vision and Image Processing. School of Computer Science and Software Engineering, The University of Western Australia. Available in: http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/Spatial/harris.m

Examples

The first example shows how to extract SURF descriptors from a standard test image:

// Let's load an example image, such as Lena,
// from a standard dataset of example images:
var images = new TestImages(path: localPath);
Bitmap lena = images["lena.bmp"];

// Create a new SURF with the default parameter values:
var surf = new SpeededUpRobustFeaturesDetector(threshold: 0.0002f, octaves: 5, initial: 2);

// Use it to extract the SURF point descriptors from the Lena image:
List<SpeededUpRobustFeaturePoint> descriptors = surf.ProcessImage(lena);

// We can obtain the actual double[] descriptors using
double[][] features = descriptors.Apply(d => d.Descriptor);

// Now those descriptors can be used to represent the image itself, such
// as for example, in the Bag-of-Visual-Words approach for classification.

The second example shows how to use SURF descriptors as part of a BagOfVisualWords (BoW) pipeline for image classification:

// Ensure results are reproducible
Accord.Math.Random.Generator.Seed = 0;

// The Bag-of-Visual-Words model converts images of arbitrary 
// size into fixed-length feature vectors. In this example, we
// will be setting the codebook size to 10. This means all feature
// vectors that will be generated will have the same length of 10.

// By default, the BoW object will use the sparse SURF as the 
// feature extractor and K-means as the clustering algorithm.

// Create a new Bag-of-Visual-Words (BoW) model
var bow = BagOfVisualWords.Create(numberOfWords: 10);
// Note: a simple BoW model can also be created using
// var bow = new BagOfVisualWords(numberOfWords: 10);

// Get some training images
Bitmap[] images = GetImages();

// Compute the model
bow.Learn(images);

// After this point, we will be able to translate
// images into double[] feature vectors using
double[][] features = bow.Transform(images);

// We can also check some statistics about the dataset:
int numberOfImages = bow.Statistics.TotalNumberOfInstances; // 6

// Statistics about all the descriptors that have been extracted:
int totalDescriptors = bow.Statistics.TotalNumberOfDescriptors; // 4132
double totalMean = bow.Statistics.TotalNumberOfDescriptorsPerInstance.Mean; // 688.66666666666663
double totalVar = bow.Statistics.TotalNumberOfDescriptorsPerInstance.Variance; // 96745.866666666669
IntRange totalRange = bow.Statistics.TotalNumberOfDescriptorsPerInstanceRange; // [409, 1265]

// Statistics only about the descriptors that have been actually used:
int takenDescriptors = bow.Statistics.NumberOfDescriptorsTaken; // 4132
double takenMean = bow.Statistics.NumberOfDescriptorsTakenPerInstance.Mean; // 688.66666666666663
double takenVar = bow.Statistics.NumberOfDescriptorsTakenPerInstance.Variance; // 96745.866666666669
IntRange takenRange = bow.Statistics.NumberOfDescriptorsTakenPerInstanceRange; // [409, 1265]
// Now, the features can be used to train any classification
// algorithm as if they were the images themselves. For example,
// let's assume the first three images belong to a class and
// the second three to another class. We can train an SVM using

int[] labels = { -1, -1, -1, +1, +1, +1 };

// Create the SMO algorithm to learn a Linear kernel SVM
var teacher = new SequentialMinimalOptimization<Linear>()
{
    Complexity = 10000 // make a hard margin SVM
};

// Obtain a learned machine
var svm = teacher.Learn(features, labels);

// Use the machine to classify the features
bool[] output = svm.Decide(features);

// Compute the error between the expected and predicted labels
double error = new ZeroOneLoss(labels).Loss(output);
See Also