F_VN_BilateralFilter

F_VN_BilateralFilter 1:

Apply a Bilateral filter to smooth the image but preserve edges.
Can use available TwinCAT Job Tasks for executing parallel code regions.

Syntax

Definition:

FUNCTION F_VN_BilateralFilter : HRESULT
VAR_INPUT
    ipSrcImage  : ITcVnImage;
    ipDestImage : Reference To ITcVnImage;
    nDiameter   : DINT;
    fSigmaColor : LREAL;
    fSigmaSpace : LREAL;
    hrPrev      : HRESULT;
END_VAR

F_VN_BilateralFilter 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image

ipDestImage

Reference To ITcVnImage

Destination image (Must be different from ipSrcImage! An appropriate destination image will be created if required.)

nDiameter

DINT

Diameter of the pixel neighborhood used for filtering (e.g. 5, 7, 9). If <= 0, it is automatically chosen dependend on fSigmaSpace.

fSigmaColor

LREAL

Sigma used for color space filtering (> 0). A larger value means that farther colors are mixed together.

fSigmaSpace

LREAL

Sigma used for coordinate space filtering (> 0). A larger value means that farther pixels can influence each other.

hrPrev

HRESULT

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

F_VN_BilateralFilter 3: Return value

HRESULT

Further information

The function F_VN_BilateralFilter applies a bilateral filter to the original image. The filter smooths the image and reduces noise while retaining the edges in the image.

Parameter

Original image

The original image ipSrcImage must be of the element type TCVN_ET_USINT or a floating point type and have 1 or 3 channels.

Result image

The result image ipDestImage must be a different interface pointer to the original image ipSrcImage!

Filter diameter

The filter diameter nDiameter determines the size of a filter area. An odd number is expected. If nDiameter = 0, then the filter diameter is automatically calculated on the basis of fSigmaSpace.

Color area

This value may not be 0.

Room area

This value may not be 0.

Expert parameters

Further parameters can be found in the expert version F_VN_BilateralFilterExp.

Application

An application of this function can look like this, for example:

hr := F_VN_BilateralFilter(
    ipSrcImage      :=  ipImage,
    ipDestImage     :=  ipImageRes,
    nDiameter       :=  nDiameter,
    fSigmaColor     :=  fSigmaColor,
    fSigmaSpace     :=  fSigmaSpace,
    hrPrev          :=  hr
);

The unprocessed original image (1st row) already exhibits fine structures on the surface of the gear wheels in the detail. In order to illustrate the effects of the filters, additional disturbances were added to the original image by Gauss noise (2nd row) and salt-and-pepper noise (3rd row).

Original images

Result images:

Diameter = 7

Sigma = 100

F_VN_BilateralFilter 4:

F_VN_BilateralFilter 5:

F_VN_BilateralFilter 6:

F_VN_BilateralFilter 7:

F_VN_BilateralFilter 8:

F_VN_BilateralFilter 9:

Samples

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