HistogramsOfOrientedGradients Class |
Namespace: Accord.Imaging
The HistogramsOfOrientedGradients type exposes the following members.
Name | Description | |
---|---|---|
HistogramsOfOrientedGradients |
Initializes a new instance of the HistogramsOfOrientedGradients class.
| |
HistogramsOfOrientedGradients(Int32, Int32, Int32) |
Initializes a new instance of the HistogramsOfOrientedGradients class.
|
Name | Description | |
---|---|---|
BinWidth |
Gets the width of the histogram bin. This property is
computed as (2.0 * System.Math.PI) / numberOfBins.
| |
BlockSize |
Gets the size of a block, in pixels. Default is 3.
| |
CellSize |
Gets the size of a cell, in pixels. Default is 6.
| |
Direction |
Gets the matrix of orientations generated in
the last call to Transform(Bitmap).
| |
Histograms |
Gets the histogram computed at each cell.
| |
Magnitude |
Gets the matrix of magnitudes generated in
the last call to Transform(Bitmap).
| |
Normalize |
Gets or sets whether to normalize final
histogram feature vectors. Default is true.
| |
NumberOfBins |
Gets the number of histogram bins. Default is 9.
| |
NumberOfInputs |
Returns -1.
(Inherited from BaseFeatureExtractorTFeature.) | |
NumberOfOutputs |
Gets the dimensionality of the features generated by this extractor.
(Inherited from BaseFeatureExtractorTFeature.) | |
SupportedFormats |
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.) |
Name | Description | |
---|---|---|
Clone |
Creates a new object that is a copy of the current instance.
(Inherited from BaseFeatureExtractorTFeature.) | |
Clone(ISetPixelFormat) |
Creates a new object that is a copy of the current instance.
(Overrides BaseFeatureExtractorTFeatureClone(ISetPixelFormat).) | |
Dispose |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from BaseFeatureExtractorTFeature.) | |
Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources.
(Inherited from BaseFeatureExtractorTFeature.) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
InnerTransform |
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).) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ProcessImage(Bitmap) | Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseFeatureExtractorTFeature.) | |
ProcessImage(BitmapData) | Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseFeatureExtractorTFeature.) | |
ProcessImage(UnmanagedImage) | Obsolete.
Obsolete. Please use the Transform(Bitmap) method instead.
(Inherited from BaseFeatureExtractorTFeature.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Transform(Bitmap) |
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.) | |
Transform(Bitmap) |
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.) | |
Transform(UnmanagedImage) |
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.) | |
Transform(UnmanagedImage) |
Applies the transformation to an input, producing an associated output.
(Inherited from BaseFeatureExtractorTFeature.) | |
Transform(Bitmap, IEnumerableTFeature) |
Applies the transformation to a set of input vectors,
producing an associated set of output vectors.
(Inherited from BaseFeatureExtractorTFeature.) | |
Transform(UnmanagedImage, IEnumerableTFeature) |
Applies the transformation to a set of input vectors,
producing an associated set of output vectors.
(Inherited from BaseFeatureExtractorTFeature.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(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.) | |
ToT | 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.) |
References:
The first example shows how to extract HOG 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 Histogram of Oriented Gradients with the default parameter values: var hog = new HistogramsOfOrientedGradients(numberOfBins: 9, blockSize: 3, cellSize: 6); // Use it to extract descriptors from the Lena image: List<double[]> descriptors = hog.ProcessImage(lena); // 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 HOG 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 3. This means all feature // vectors that will be generated will have the same length of 3. // By default, the BoW object will use the sparse SURF as the // feature extractor and K-means as the clustering algorithm. // In this example, we will use the Local Binary Pattern (LBP) // feature extractor and the Binary-Split clustering algorithm. // However, this is just an example: the best features and the // best clustering algorithm might need to be found through // experimentation. Please also try with KMeans first to obtain // a baseline value. // Create a new Bag-of-Visual-Words (BoW) model using LBP features var bow = BagOfVisualWords.Create(new LocalBinaryPattern(), new BinarySplit(3)); // Since we are using generics, we can setup properties // of the binary split clustering algorithm directly: bow.Clustering.ComputeCovariances = false; bow.Clustering.ComputeProportions = false; bow.Clustering.ComputeError = false; // 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);
// 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<Gaussian>() { Complexity = 100 // 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); // should be 0