F_VN_AdaptiveThresholdExp

F_VN_AdaptiveThresholdExp 1:

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

F_VN_AdaptiveThresholdExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

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

ETcVnAdaptiveThresholdMethod

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

ETcVnThresholdType

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

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

F_VN_AdaptiveThresholdExp 3: Return value

HRESULT

Weiterführende Informationen

Die Funktion F_VN_AdaptiveThresholdExp ist die Expert-Variante von F_VN_AdaptiveThreshold. Sie enthält zusätzliche Parameter.

Parameter

Eingangsbild

Das Eingangsbild ipSrcImage muss ein 1-kanaliges Grauwertbild mit einer Bittiefe von 8 Bit (USINT) sein.

Ergebnisbild

Das binäre Ergebnisbild ipDestImage hat das gleiche Format wie das Eingangsbild. Die Pixel haben entweder den Wert 0 oder den Zielwert fMaxValue.

Zielwert

Der Zielwert fMaxValue definiert, welchen Wert die Pixel bekommen sollen, die das Schwellwert-Kriterium erfüllen. Wenn das Ergebnisbild nur aus schwarzen und weißen Pixeln bestehen soll, muss hier der Maximal-Wert des Element-Typs des Eingangsbilds eingestellt werden. Dies entspricht (2^d)-1, wobei d die Bittiefe des Element-Typs darstellt; z. B. (2^8)-1=255 bei 8-Bit-Bildern.

Schwellwert-Methode

Die Schwellwert-Methode eAdaptiveMethod legt fest, ob der adaptive Schwellwert als Durchschnitt oder als Gauss-gewichtete Summe berechnet wird. Dazu stehen in dem Enum ETcVnAdaptiveThresholdMethod die beiden Werte TCVN_ATM_MEAN und TCVN_ATM_GAUSSIAN zur Verfügung.

Schwellwert-Invertierung

Der Parameter eThresholdType legt fest, ob das Ergebnisbild invertiert werden soll oder nicht. Daher werden an dieser Stelle aus dem Enum ETcVnThresholdType nur die beiden Werte TCVN_TT_BINARY und TCVN_TT_BINARY_INV unterstützt.

Schwellwert-Nachbarschaftsgröße

Der Parameter nBlockSize legt die Größe der Nachbarschaft fest, die für die Berechnung des lokalen Schwellwerts betrachtet wird. Der Parameter muss ungerade sein (3, 5, 7, …).

Schwellwert-Anpassung

Der konstante Wert fConstant wird von jedem lokalen Durchschnittswert abgezogen. Das Ergebnis ist der lokale Schwellwert, der zur Berechnung des Ergebnisbildes verwendet wird.

Anwendung

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.44 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision