F_VN_Histogram

F_VN_Histogram 1:

Calculate the (multi-channel) histogram of an image.
Can use available TwinCAT Job Tasks for executing parallel code regions.

Syntax

Definition:

FUNCTION F_VN_Histogram : HRESULT
VAR_INPUT
    ipSrcImage      : ITcVnImage;
    ipDestHistogram : Reference To ITcVnContainer;
    hrPrev          : HRESULT;
END_VAR

F_VN_Histogram 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image

ipDestHistogram

Reference To ITcVnContainer

Returns a container with a multi-channel histogram, where every channel is represented as a vector of UDINT (ContainerType_Vector_Vector_UDINT. Non-zero interface pointers are reused.)

hrPrev

HRESULT

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

F_VN_Histogram 3: Return value

HRESULT

Further information

The function F_VN_Histogram calculates the histogram of the input image channel by channel.

Parameter

Input image

The input image ipSrcImage can have any format.

Histogram

The calculated multichannel histogram is returned as a container ipDestHistogram of the type ContainerType_Vector_Vector_UDINT. Each sub-element corresponds to the histogram of one channel. Each container of the histogram is represented as a UDINT, which specifies the number of pixels belonging to the container.

Expert parameters

The expert version F_VN_HistogramExp contains additional parameters.

Application

The determination of the most frequently occurring pixel value in a grayscale image looks like this, for example:

VAR
    ipDestHistograms    :   ITcVnContainer;
    ipSingleHistogram   :   ITcVnContainer;
    nIndex              :   ULINT;
    ipIterator          :   ITcVnBidirectionalIterator;
END_VAR

hr := F_VN_Histogram(
    ipSrcImage      :=  ipImageIn,
    ipDestHistogram :=  ipHistograms,
    hrPrev          :=  hr
);

hr := F_VN_GetAt_ITcVnContainer(ipHistograms, ipSingleHistogram, 0, hr);
hr := F_VN_MaxElement(ipSingleHistogram, ipIterator, nIndex, hr);
// nIndex now contains the most frequent pixel value in ipImageIn.

Samples

Required License

TC3 Vision Base

System Requirements