F_VN_CannyEdgeDetection
Find edges using the Canny edge detection algorithm.
Can use available TwinCAT Job Tasks for executing parallel code regions.
Syntax
Definition:
FUNCTION F_VN_CannyEdgeDetection : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipDestImage : Reference To ITcVnImage;
fThresholdLow : LREAL;
fThresholdHigh : LREAL;
hrPrev : HRESULT;
END_VAR
Inputs
Name |
Type |
Description |
---|---|---|
ipSrcImage |
Source image (elements of type USINT) | |
ipDestImage |
Reference To ITcVnImage |
Destination image (elements of type USINT. An appropriate destination image will be created if required.) |
fThresholdLow |
LREAL |
Low threshold |
fThresholdHigh |
LREAL |
High threshold |
hrPrev |
HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Further information
This function finds edges in an image and illustrates them by white lines on a black background. In addition, this expert version F_VN_CannyEdgeDetectionExp exists with advanced parameterization options.
Algorithm
The Canny Edge edge detection is a multi-stage algorithm for the most robust edge detection possible. It consists of the following steps:
- Reduction of noise by means of Gaussian filter.
- Edge finding by means of Sobel operator.
- Line thinning by means of non-maximum suppression, i.e. the resulting lines are 1 px thick.
- Hysteresis, so that only thick lines remain (see Threshold parameters below).
Parameter
Original image
A 1-channel 8-bit intensity image (pixel format TCVN_ET_USINT
) is expected for the original image ipSrcImage
. You can therefore use a grayscale image or the individual channels of a color image.
Result image
The result image ipDestImage
has the same format.
Threshold values
The two thresholds fThresholdLow
and fThresholdHigh
determine which of the edges found are accepted: Pixels with a gradient higher than fThresholdHigh
are accepted. Pixels with a color gradient below fThresholdLow
are discarded. Pixels with gradients in between are only accepted if they are linked to already accepted pixels.
The two thresholds make a flexible setting possible. A hard threshold is also realizable by setting both values the same.
Important edge information may be lost if you set the thresholds too high. If the thresholds are too low, noise and other irrelevant information might be interpreted as edges.
Application
hr := F_VN_CannyEdgeDetection(
ipSrcImage := ipImageIn,
ipDestImage := ipImageWork,
fThresholdLow := 0,
fThresholdHigh := 200,
hr
);
Required License
TC3 Vision Base
System Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT V3.1.4024.54 or later | PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU | Tc3_Vision |