F_VN_DistanceTransformation
Calculates the distance transformation, which is the distance to the closest zero pixel in a binary image.
Syntax
Definition:
FUNCTION F_VN_DistanceTransformation : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipDestImage : Reference To ITcVnImage;
eDistanceType : ETcVnDistanceType;
eMaskSize : ETcVnDistanceTransformationMask;
hrPrev : HRESULT;
END_VAR
Inputs
Name |
Type |
Description |
---|---|---|
ipSrcImage |
Source image (USINT, 1 channel) | |
ipDestImage |
Reference To ITcVnImage |
Destination image (REAL, 1 channel. An appropriate destination image will be created if required.) |
eDistanceType |
Distance computation method (supported: L1, L2, C) | |
eMaskSize |
Size of the distance transformation mask | |
hrPrev |
HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Further information
This function performs the distance transformation of an image. In addition, there is an expert version F_VN_DistanceTransformationExp with advanced parameterization options.
Parameter
The following parameters are available in the basic version:
Original image
A 1-channel 8-bit image (element type TCVN_ET_USINT
) is expected for the original image ipSrcImage
. Other image formats must first be converted.
Result image
The result image ipDestImage
is returned with the element type TCVN_ET_REAL
. The value of each pixel describes the distance between the respective pixel and the nearest 0-value pixel in the original image.
Display in the ADS Image Watch In order to be able to display the result image in the ADS Image Watch, it must first be converted into a compatible image format. Depending on the use case, it may be useful to scale the pixel values. |
Distance type
The distance type eDistanceType
determines the equation with which the distance between a pixel and the nearest 0-value pixel is calculated. The following distance types from the enum ETcVnDistanceType are supported:
- TCVN_DT_L1
- TCVN_DT_L2
- TCVN_DT_C
Mask sizes
The mask size eMaskSize
describes the approximation of the Euclidean distance if the L2 standard is selected as the distance type.
- TCVN_DTM_PRECISE: The Euclidean distance is calculated precisely.
- TCVN_DTM_3: The Euclidean distance is approximated as the sum of distance elements within a 3x3 mask (horizontal, vertical and diagonal).
- TCVN_DTM_5: The Euclidean distance is approximated as the sum of distance elements within a 5x5 mask (horizontal, vertical, diagonal and knight's move (as in chess)).
The mask size has no effect with the distance types L1 and C. Instead, a 3x3 mask is always used internally.
Application
An application of this function can look like this, for example:
// convert to binary image
hr := F_VN_Threshold(ipImageIn, ipImageWork, 128, 255, TCVN_TT_BINARY, hr);
// apply distance transformation
hr := F_VN_DistanceTransformation(
ipSrcImage := ipImageWork,
ipDestImage := ipImageWork,
eDistanceType := TCVN_DT_C,
eMaskSize := TCVN_DTM_3,
hr
);
// convert image to display it in ADS Image Watch
hr := F_VN_ConvertElementType(ipImageWork, ipImageWork, TCVN_ET_USINT, hr);
Original image | Binary image | Result image |
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 |