F_VN_GaussianFilter

F_VN_GaussianFilter 1:

Apply a Gaussian filter to smooth the image.
Can use available TwinCAT Job Tasks for executing parallel code regions.

Syntax

Definition:

FUNCTION F_VN_GaussianFilter : HRESULT
VAR_INPUT
    ipSrcImage    : ITcVnImage;
    ipDestImage   : Reference To ITcVnImage;
    nFilterWidth  : UDINT;
    nFilterHeight : UDINT;
    hrPrev        : HRESULT;
END_VAR

F_VN_GaussianFilter 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image

ipDestImage

Reference To ITcVnImage

Destination image (An appropriate destination image will be created if required.)

nFilterWidth

UDINT

Filter width in pixels (1, 3, 5, 7, ...)

nFilterHeight

UDINT

Filter height in pixels (1, 3, 5, 7, ...)

hrPrev

HRESULT

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

F_VN_GaussianFilter 3: Return value

HRESULT

Further information

The function F_VN_GaussianFilter applies a Gaussian filter to the input image.

Algorithm

The Gaussian filter is often used in image processing to reduce noise or smooth an image. Each pixel is replaced by the weighted average of its environment, removing smaller details but preserving larger ones. The larger the filter, the more smoothed the image will be (and therefore appears more blurred).

Parameter

Input image

The input image ipSrcImage may have any available format.

Result image

The result image ipDestImage is given the same format as the input image ipSrcImage.

Filter size

The size of the Gauss filter is described in the X direction by nFilterWidth and in the Y direction by nFilterHeight. The size specifications must be odd numbers, as there must always be a central pixel.

Expert parameters

The expert version F_VN_GaussianFilterExp contains additional parameters.

Application

hr := F_VN_GaussianFilter(
    ipSrcImage      :=  ipImageIn,
    ipDestImage     :=  ipImageRes,
    nFilterWidth    :=  7,
    nFilterHeight   :=  7,
    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

F_VN_GaussianFilter 4:

F_VN_GaussianFilter 5:

F_VN_GaussianFilter 6:

F_VN_GaussianFilter 7:

F_VN_GaussianFilter 8:

F_VN_GaussianFilter 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