HoughLineTransformation Class |
Namespace: Accord.Imaging
The HoughLineTransformation type exposes the following members.
Name | Description | |
---|---|---|
HoughLineTransformation |
Initializes a new instance of the HoughLineTransformation class.
|
Name | Description | |
---|---|---|
LinesCount |
Found lines count.
| |
LocalPeakRadius |
Radius for searching local peak value.
| |
MaxIntensity |
Maximum found intensity in Hough map.
| |
MinLineIntensity |
Minimum line's intensity in Hough map to recognize a line.
| |
StepsPerDegree |
Steps per degree.
|
Name | Description | |
---|---|---|
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.) | |
GetLinesByRelativeIntensity |
Get lines with relative intensity higher then specified value.
| |
GetMostIntensiveLines |
Get specified amount of lines with highest intensity.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ProcessImage(Bitmap) |
Process an image building Hough map.
| |
ProcessImage(BitmapData) |
Process an image building Hough map.
| |
ProcessImage(UnmanagedImage) |
Process an image building Hough map.
| |
ProcessImage(Bitmap, Rectangle) |
Process an image building Hough map.
| |
ProcessImage(BitmapData, Rectangle) |
Process an image building Hough map.
| |
ProcessImage(UnmanagedImage, Rectangle) |
Process an image building Hough map.
| |
ToBitmap |
Convert Hough map to bitmap.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.) |
The class implements Hough line transformation, which allows to detect straight lines in an image. Lines, which are found by the class, are provided in polar coordinates system - lines' distances from image's center and lines' slopes are provided. The pole of polar coordinates system is put into processing image's center and the polar axis is directed to the right from the pole. Lines' slope is measured in degrees and is actually represented by angle between polar axis and line's radius (normal going from pole to the line), which is measured in counter-clockwise direction.
Note |
---|
Found lines may have negative radius. This means, that the line resides in lower part of the polar coordinates system and its Theta value should be increased by 180 degrees and radius should be made positive. |
The class accepts binary images for processing, which are represented by 8 bpp grayscale images. All black pixels (0 pixel's value) are treated as background, but pixels with different value are treated as lines' pixels.
See also documentation to HoughLine class for additional information about Hough Lines.
The following example shows how to apply the Hough Line Transform. The example will apply it to the "sudoku.png" test image from OpenCV, as shown below:
// Let's use a standard test image to show how to apply // the Hough image transform. For this, we can load an // example image using the TestImages class: var testImages = new Accord.DataSets.TestImages(basePath); // We'll use the sudoku test image from OpenCV: Bitmap image = testImages.GetImage("sudoku.png"); // Convert it to binary and mark the possible lines // in white so it can be processed by the transform var sequence = new FiltersSequence( Grayscale.CommonAlgorithms.BT709, new NiblackThreshold(), new Invert() ); // Apply the sequence of filters above: Bitmap binaryImage = sequence.Apply(image); // Finally, we can create a Line Hough Transform: var lineTransform = new HoughLineTransformation(); // and then apply it to the binary image: lineTransform.ProcessImage(binaryImage); // the output of the transform can be seen using Bitmap houghLineImage = lineTransform.ToBitmap(); // For visualization purposes, we can either display the result of the // transform on the screen or save it to disk to be visualized later: // ImageBox.Show(houghLineImage); // houghLineImage.Save("hough-output.png");
Input image after applying the filter sequence:
Output image after the Hough transform:
// Now, let's say we would like to retrieve the lines and use them // for further processing. First, the lines can be ordered by their // relative intensity using HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.7); // Then, let's plot them on top of the input image. Since we will // apply many operations to a single image, it is better to first // convert it to an UnmanagedImage object to avoid having to lock // the image into memory multiple times. UnmanagedImage unmanagedImage = UnmanagedImage.FromManagedImage(image); // Finally, plot them in order: foreach (HoughLine line in lines) { line.Draw(unmanagedImage, color: Color.Red); } // ImageBox.Show(unmanagedImage); // unmanagedImage.ToManagedImage().Save("hough-lines.png");
Hough lines drawn over the input image: