F_VN_AdaptiveThresholdExp
Apply an adaptive threshold to a gray level image. (expert function)
Can return partial results when canceled by Watchdog.
Syntax
Definition:
FUNCTION F_VN_AdaptiveThresholdExp : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipDestImage : Reference To ITcVnImage;
fMaxValue : LREAL;
eAdaptiveMethod : ETcVnAdaptiveThresholdMethod;
eThresholdType : ETcVnThresholdType;
nBlockSize : UDINT;
fConstant : LREAL;
hrPrev : HRESULT;
END_VAR
Inputs
Name |
Type |
Description |
---|---|---|
ipSrcImage |
Source image (1 channel, elements of type USINT) | |
ipDestImage |
Reference To ITcVnImage |
Destination image (An appropriate destination image will be created if required.) |
fMaxValue |
LREAL |
Value assigned to pixels for which the threshold condition is true |
eAdaptiveMethod |
Adaptive threshold method to be applied (MEAN: threshold value will be calculated as a mean of the nBlockSize x nBlockSize neighborhood of (x,y) minus fConstant. GAUSSIAN: threshold value is a weighted sum (cross-correlation with a Gaussian window) of the nBlockSize x nBlockSize neighborhood of (x,y) minus fConstant. | |
eThresholdType |
Threshold type to be applied (only BINARY and BINARY_INV are supported) | |
nBlockSize |
UDINT |
Size of the pixel neighborhood to calculate the local threshold (3, 5, 7, ...) |
fConstant |
LREAL |
Constant that is subtracted from the weighted mean of the pixel neighborhood, which leads to the local threshold |
hrPrev |
HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
Further information
The function F_VN_AdaptiveThresholdExp
is the expert version of F_VN_AdaptiveThreshold. It contains additional parameters.
Parameter
Input image
The input image ipSrcImage
must be a 1-channel grayscale image with a bit depth of 8 bits (USINT
).
Result image
The binary result image ipDestImage
has the same format as the input image. The pixels have either the value 0
or the target value fMaxValue
.
Target value
The target value fMaxValue
defines which value should be given to the pixels that fulfil the threshold criterion. If the result image is to consist only of black and white pixels, then the maximum value of the element type of the input image must be set here. This corresponds to (2^d)-1
, where d represents the bit depth of the element type; e.g. (2^8)-1=255
with 8-bit images.
Threshold method
The threshold method eAdaptiveMethod defines whether the adaptive threshold is calculated as an average or as a Gaussian weighted sum. The two values TCVN_ATM_MEAN
and TCVN_ATM_GAUSSIAN
are available for this in the enum ETcVnAdaptiveThresholdMethod.
Threshold inversion
The parameter eThresholdType specifies whether or not the result image should be inverted. Therefore, only the two values TCVN_TT_BINARY
and TCVN_TT_BINARY_INV
from the enum ETcVnThresholdType are supported at this point.
Threshold neighborhood size
The parameter nBlockSize
defines the size of the neighborhood that is considered for the calculation of the local threshold. The parameter must be an odd number (3, 5, 7, etc.).
Threshold adjustment
The constant value fConstant
is subtracted from each local average value. The result is the local threshold that is used for the calculation of the result image.
Application
hr := F_VN_AdaptiveThreshold(
ipSrcImage := ipImageIn,
ipDestImage := ipImageRes,
fMaxValue := 255, // max value of 8-bit image: (2^8)-1=255
eAdaptiveMethod := TCVN_ATM_MEAN,
eThresholdType := TCVN_TT_BINARY_INV,
nBlockSize := 5,
fConstant := 10,
hrPrev := 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 |