Core Optical, Inc.
XYGradientEdgeDetector GetEdgeMagnitudeImage Method Industrial Strength, Scientific Grade
Returns a OnlineBitmapSource image of the gradient magnitude of the source data.

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

public BitmapSource GetEdgeMagnitudeImage(
	SourceData sourceData,
	int channel,
	GrayBitDepth grayBitDepth = GrayBitDepth.EightBit,
	Int32Rect regionOfInterest = null,
	GammaEncoding gammaEncoding = GammaEncoding.None


Type: PrecisionImage SourceData
A SourceData type containing the image data.
Type: OnlineSystem Int32
An OnlineInt32 type indicating the data channel to process.
grayBitDepth (Optional)
Type: PrecisionImage GrayBitDepth
A GrayBitDepth enumerator indicating the bit-depth of the returned grayscal BitmapSource image.
regionOfInterest (Optional)
Type: OnlineSystem.Windows Int32Rect
An OnlineInt32Rect type indicating the region of interest. Coordinates are zero-index based. This parameter is optional and defaults to the entire image.
gammaEncoding (Optional)
Type: PrecisionImage GammaEncoding
A GammaEncoding enumeration specifying whether the otuput is gamma encoded or not. Default is GammaEncoding.None.

Return Value

A OnlineBitmapSource object containing the image of the edge-detected data. If a region of interest was specified, the returned OnlineBitmapSource object portrays the processed data of the specified region only and has the same dimensions as regionOfInterest. Otherwise, the returned OnlineBitmapSource object has the same dimensions as the source data.

OnlineSystem ArgumentNullException Thrown when sourceData is null.
OnlineSystem ArgumentOutOfRangeException Thrown when regionOfInterest is not completely contained within the source data dimensions.
OnlineSystem ArgumentOutOfRangeException Thron when channel specifies a data channel that does not exist in sourceData.

The following example generates an image of the gradient magnitude (edges) using the Scharr kernel:

using System.PrecisionImage;
using System.FeatureProcessing;

// 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);

// Display original image in Image component:
image1.Source = SourceImage;

// Instantiate a ScharrEdgeDetector object to process the data: 
ScharrEdgeDetector edgeDetector = new ScharrEdgeDetector();

// Generate the edge image and display:
image2.Source = edgeDetector.GetEdgeImage(imageData, 0);

The above example generates the following images:

See Also