Click or drag to resize
Accord.NET (logo)

HoughLineTransformation Class

Hough line transformation.
Inheritance Hierarchy
SystemObject
  Accord.ImagingHoughLineTransformation

Namespace:  Accord.Imaging
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public class HoughLineTransformation
Request Example View Source

The HoughLineTransformation type exposes the following members.

Constructors
  NameDescription
Public methodHoughLineTransformation
Initializes a new instance of the HoughLineTransformation class.
Top
Properties
  NameDescription
Public propertyLinesCount
Found lines count.
Public propertyLocalPeakRadius
Radius for searching local peak value.
Public propertyMaxIntensity
Maximum found intensity in Hough map.
Public propertyMinLineIntensity
Minimum line's intensity in Hough map to recognize a line.
Public propertyStepsPerDegree
Steps per degree.
Top
Methods
  NameDescription
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 methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLinesByRelativeIntensity
Get lines with relative intensity higher then specified value.
Public methodGetMostIntensiveLines
Get specified amount of lines with highest intensity.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProcessImage(Bitmap)
Process an image building Hough map.
Public methodProcessImage(BitmapData)
Process an image building Hough map.
Public methodProcessImage(UnmanagedImage)
Process an image building Hough map.
Public methodProcessImage(Bitmap, Rectangle)
Process an image building Hough map.
Public methodProcessImage(BitmapData, Rectangle)
Process an image building Hough map.
Public methodProcessImage(UnmanagedImage, Rectangle)
Process an image building Hough map.
Public methodToBitmap
Convert Hough map to bitmap.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
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

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 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.

Examples

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:

See Also