F_VN_CheckColorRange
Check if the pixel values of an image lie in a given range. The destination image has the same size as the source image but only one channel with a pixel element size of 8 bit. Its elements are set to 255 if the corresponding pixels of the source image are in the checked range and set to 0 otherwise.
Syntax
Definition:
FUNCTION F_VN_CheckColorRange : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipDestImage : Reference To ITcVnImage;
END_VAR
VAR_IN_OUT
aLowerBounds : TcVnVector4_LREAL;
aUpperBounds : TcVnVector4_LREAL;
END_VAR
VAR_INPUT
hrPrev : HRESULT;
END_VAR
Inputs
|
Name |
Type |
Description |
|---|---|---|
|
ipSrcImage |
Source image | |
|
ipDestImage |
Reference To ITcVnImage |
Destination image (An appropriate destination image will be created if required.) |
|
hrPrev |
HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
In/Outputs
|
Name |
Type |
Description |
|---|---|---|
|
aLowerBounds |
Channel-wise lower bounds (Unused channels are ignored.) | |
|
aUpperBounds |
Channel-wise upper bounds (Unused channels are ignored.) |
Further information
The F_VN_CheckColorRange function segments the input image with regard to a specific value range. This means that it does not matter which color space is used, as the segmentation is purely numerical.
- Image pixels that lie within the range are assigned the maximum value 255 (white).
- Image pixels that lie outside of the color spectrum are given the value
0(black).
Parameter
Input image
The input image ipSrcImage can have any format.
Result image
The result image ipDestImage returns the segmented 1-channel 8-bit binary image.
Range of Values
The value range to be segmented is defined by the lower limit aLowerBounds and upper limit aUpperBounds.
For cyclic value ranges such as the Hue channel in HSV space, the lower limit value can exceed the upper limit value in order to segment color ranges across the zero crossing. A range from the lower limit [250, ...] to the upper limit [5, ...] corresponds to the combination of a function call with [250, ...] - [MAX, ...] and [0, ...] - [5, ...]. This makes it possible to directly select color tones that lie in the transition of the value range, such as the red range (+-20° around 0°) in the Hue channel, with a function call.
![]() | Initialize boundary vectors Always be sure to initialize the boundary vectors with at least as many elements as the input image has channels. For example, if you segment a 4-channel image (e.g. with alpha channel) and initialize the color vectors with only three elements, the fourth elements of the vectors are 0 and the result image turns black. |
Application
For reliable color segmentations, it is generally advisable to work in a color space other than the additive RGB space. For example, in HSV space, hue (H) is separated from lightness (V) and saturation (S), which means that color differentiation is typically less sensitive to fluctuations in lighting.
The segmentation of an HSV image (HSV_FULL) for a red color spectrum looks like this, for example:
VAR
aLower : TcVnVector4_LREAL := [250, 150, 100];
aUpper : TcVnVector4_LREAL := [5, 255, 255];
END_VAR
hr := F_VN_CheckColorRange(
ipSrcImage := ipImageIn,
ipDestImage := ipImageRes,
aLowerBounds := aLower,
aUpperBounds := aUpper,
hrPrev := hr);Examples
Related functions
- F_VN_DoubleThreshold for binary segmentation on the basis of double threshold values using morphological reconstruction
- F_VN_Threshold for binary segmentation on the basis of a threshold value
- F_VN_AdaptiveThreshold for binary, adaptive segmentation
- F_VN_CheckColorRange for binary segmentation on the basis of a color spectrum
- F_VN_ReferenceColorSimilarity for binary segmentation on the basis of a color model
Required License
TC3 Vision Base
System Requirements
|
Development environment |
Target platform |
PLC libraries to include |
|---|---|---|
|
TwinCAT V3.1.4024.59 or later |
PC or CX (x64) with min. PL50, e.g. Intel 4-core Atom CPU |
Tc3_Vision |
Return value