F_VN_CannyEdgeDetection

F_VN_CannyEdgeDetection 1:

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

F_VN_CannyEdgeDetection 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

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

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_CannyEdgeDetection 3: Return value

HRESULT

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:

  1. Reduction of noise by means of Gaussian filter.
  2. Edge finding by means of Sobel operator.
  3. Line thinning by means of non-maximum suppression, i.e. the resulting lines are 1 px thick.
  4. 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
);

F_VN_CannyEdgeDetection 4:

F_VN_CannyEdgeDetection 5:

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