Threshold

Block Category: Operations

Input Image Format

Input Image Requirements: None

Description: Thresholding is the simplest method of image segmentation. It is used for thresholding color images (RGB, HSV, HLS) and gray scale images.

In general, for a gray scale image, the Threshold block creates binary images (white and black) as the output. For a color image, the binary output image represents a range of intensity. Thus, the objective of binarization is to mark the pixel foreground region with a single intensity and the background region with different intensities.

With the Threshold block, there are two possible comparison outcomes performed at every pixel location based on the pixel value ratio. If the pixel value is greater than the specified threshold value:

      For a gray scale image: it is assigned one value (bright color (pure white)) else it is assigned another value (dark color (black)).

      For an HSV color image: it is assigned one value (bright color (red/magenta)) else it is assigned another value (dark color (blue/cyan)).

      For an HLS color image: it is assigned one value (mix with white to lighten the value (green/cyan)) else it is assigned another value (mix with black to darken the value (red/magenta)).

Maximum Binary Value: Indicates the maximum value (0 – 255) of the pixel for the threshold operation.

Use input connector values to specify the threshold value and max binary value: Adds two input connectors to the block to dynamically change the threshold value and maximum binary value.

Threshold Type

Binary: If the source pixel value is greater than the threshold value, the new pixel value is set to the specified Max Binary Value; otherwise, the pixel value is set to 0.

Binary Invert: If the source pixel value is greater than the threshold value, the new pixel value is set to a 0; otherwise, the pixel value is set to the Max Binary Value.

Threshold to Zero: If the source pixel value is greater than the threshold value, the new pixel value is set to 0; otherwise, the pixel value is set to the source pixel value.

Threshold to Zero Inverted: If the source pixel value is greater than the maximum threshold value, the new pixel value is set to 0; otherwise, the pixel value is set to the source pixel value.

Threshold Truncated: If the source pixel value is greater than the threshold value, the new pixel value is set to the threshold; otherwise, the pixel value is set to 0.

Threshold Value: Indicates the minimum pixel value (0 – 255) for the threshold operation.

Example

In the following example, four different threshold operations are performed on the input image: RGB to Gray; RGB; RGB to HLS; and RGB to HSV.