C# Class AForge.Imaging.HoughLineTransformation

Hough line transformation.

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.

Found lines may have negative radius. This means, that the line resides in lower part of the polar coordinates system and its HoughLine.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.

Sample usage:

HoughLineTransformation lineTransform = new HoughLineTransformation( ); // apply Hough line transofrm lineTransform.ProcessImage( sourceImage ); Bitmap houghLineImage = lineTransform.ToBitmap( ); // get lines using relative intensity HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity( 0.5 ); foreach ( HoughLine line in lines ) { // ... }

Initial image:

Hough line transformation image:

Datei anzeigen Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Public Methods

Method Description
GetLinesByRelativeIntensity ( double minRelativeIntensity ) : AForge.Imaging.HoughLine[]

Get lines with relative intensity higher then specified value.

GetMostIntensiveLines ( int count ) : AForge.Imaging.HoughLine[]

Get specified amount of lines with highest intensity.

HoughLineTransformation ( ) : System

Initializes a new instance of the HoughLineTransformation class.

ProcessImage ( Bitmap image ) : void

Process an image building Hough map.

ProcessImage ( Bitmap image, Rectangle rect ) : void

Process an image building Hough map.

ProcessImage ( BitmapData imageData ) : void

Process an image building Hough map.

ProcessImage ( BitmapData imageData, Rectangle rect ) : void

Process an image building Hough map.

ProcessImage ( UnmanagedImage image ) : void

Process an image building Hough map.

ProcessImage ( UnmanagedImage image, Rectangle rect ) : void

Process an image building Hough map.

ToBitmap ( ) : Bitmap

Convert Hough map to bitmap.

Private Methods

Method Description
CollectLines ( ) : void

Method Details

GetLinesByRelativeIntensity() public method

Get lines with relative intensity higher then specified value.
public GetLinesByRelativeIntensity ( double minRelativeIntensity ) : AForge.Imaging.HoughLine[]
minRelativeIntensity double Minimum relative intesity of lines.
return AForge.Imaging.HoughLine[]

GetMostIntensiveLines() public method

Get specified amount of lines with highest intensity.
public GetMostIntensiveLines ( int count ) : AForge.Imaging.HoughLine[]
count int Amount of lines to get.
return AForge.Imaging.HoughLine[]

HoughLineTransformation() public method

Initializes a new instance of the HoughLineTransformation class.
public HoughLineTransformation ( ) : System
return System

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( Bitmap image ) : void
image System.Drawing.Bitmap Source image to process.
return void

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( Bitmap image, Rectangle rect ) : void
image System.Drawing.Bitmap Source image to process.
rect System.Drawing.Rectangle Image's rectangle to process.
return void

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( BitmapData imageData ) : void
imageData System.Drawing.Imaging.BitmapData Source image data to process.
return void

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( BitmapData imageData, Rectangle rect ) : void
imageData System.Drawing.Imaging.BitmapData Source image data to process.
rect System.Drawing.Rectangle Image's rectangle to process.
return void

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( UnmanagedImage image ) : void
image UnmanagedImage Source unmanaged image to process.
return void

ProcessImage() public method

Process an image building Hough map.
Unsupported pixel format of the source image.
public ProcessImage ( UnmanagedImage image, Rectangle rect ) : void
image UnmanagedImage Source unmanaged image to process.
rect System.Drawing.Rectangle Image's rectangle to process.
return void

ToBitmap() public method

Convert Hough map to bitmap.
Hough transformation was not yet done by calling /// ProcessImage() method.
public ToBitmap ( ) : Bitmap
return System.Drawing.Bitmap