Core Optical, Inc.
CannyEdgeDetector ClassIndustrial Strength, Scientific Grade
A type encapsulating all functionality associated with the Canny edge detection algorithm.
Inheritance Hierarchy

OnlineSystem Object
  PrecisionImage.FeatureProcessing CannyEdgeDetector

Namespace: PrecisionImage.FeatureProcessing
Assembly: PrecisionImage (in PrecisionImage.dll) Version: (

public class CannyEdgeDetector

The CannyEdgeDetector object is used to implement the Canny edge detector methodology. The algorithm is a 3-step process consisting of 1) filtering the input data with a gaussian smoothing kernel, 2) a non-maximal suppression process that attempts to locate the central axis of an edge, and 3) a hysteresis thresholding step to filter out non-edge locations. The edge-detection result is returned as a BinaryMask object where the edges are unmasked and the non-edge regions are masked.

The CannyEdgeDetector object has several properties that govern its performance. The LowHysteresis and HighHysteresis properties are used to set the lower and upper thresholds for the hysteresis operation. These values are normalized to the maximum gradient magnitude occuring in the dataset. All edge-magnitude values resulting from the non-maximal suppression step are retained if their magnitude exceeds the upper threshold. All values exceeding the lower threshold are retained only if they are in contact with a value that exceeds the upper threshold. The EdgeHandling enumeration controls the edge-buffering behavior during the gaussian filtering and edge gradient steps. The GaussianAutoSigma property controls whether the standard deviation of the gaussian filtering kernel is automatically determined by the kernel radii or by the user-assigned SigmaX and SigmaY properties. Lastly, the GaussianRadiusX and GaussianRadiusY control the horizontal and vertical radii of the gaussian filter mask used to prefilter the image.


The following example applies the Canny edge detection method to an image and visualizes the result using the returned edge mask.

using System.PrecisionImage;
using System.FeatureProcessing;
using PrecisionImage.BinarizationAndMorphology;

// Read the source (16-bit) image from disk and load into a SourceData object: 
Uri imageUri                   = new Uri("HorseStatueXray.tif", UriKind.Relative);
TiffBitmapDecoder imageDecoder = new TiffBitmapDecoder(imageUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource SourceImage       = imageDecoder.Frames[0];
SourceData imageData           = new SourceData(SourceImage, GammaEncoding.None);

CannyEdgeDetector edgeDetector = new CannyEdgeDetector();
edgeDetector.HighHysteresis    = 0.13f;
edgeDetector.LowHysteresis     = 0.05f;

BinaryMask edgeMask = edgeDetector.GetCannyEdgeMask(sourceData, 0);

// Invert the binary mask for unmasked (white) edges:
image1.Source = edgeMask.GetMaskImage();

The above example generates the following images:

See Also