Image Thresholding¶
Function¶
This Step filters image pixels according to the set threshold, and binarizes the pixels above and below the threshold according to the set rules.
Note
Binary images are images whose pixels have only two possible intensity values. Numerically, the two values are often 0 for black, and 255 for white.
Image binarization is the process of converting a non-binary image to a binary image.
Usage Scenario¶
This Step is a general image processing Step. It is generally used to segment pixels that meet threshold conditions on 2D images.
Input and Output¶
Parameter Description¶
This Step provides 4 segment types for separating the target object from its background.
AdaptiveThreshold: a global adaptive thresholding method that includes 2 types of operation (THRESH_BINARY, THRESH_BINARY_INV).
DualThreshold: a dual thresholding method, in which a high threshold and a low threshold are set to segment pixels that meet the conditions.
DynamicThreshold: a dynamic thresholding method that provides 4 thresholding types (Light, Dark, In Range, Out of Range) and 3 image filter methods (Mean filter, Gaussian filter, Median filter). In addition, the pixel value offset and filter kernel size can be adjusted.
Threshold: a thresholding method with a global fixed threshold. With this method, a fixed threshold is set, and 7 operation types (THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV, THRESH_OTSU, THRESH_TRIANGLE) are introduced to segment pixels that meet the conditions.
AdaptiveThreshold¶
- Operation
- Description: This parameter is used to select the operation type for separating the target object from its background.Value list: THRESH_BINARY, THRESH_BINARY_INV
THRESH_BINARY: generates a mask of pixels whose values are higher than the threshold.
THRESH_BINARY_INV: generates a mask of pixels whose values are lower than the threshold.
Default value: THRESH_BINARYTuning recommendation: Please select the operation type according to the actual requirement.
DualThreshold¶
- Low Threshold
- Description: If the low threshold is set to be lower than the high threshold, the pixels with values between the two thresholds will be set to 255, and other pixels will be set to 0. If the low threshold is set to be higher than the high threshold, the pixels with values beyond the interval set by the two thresholds will be set to 255, and other pixels will be set to 0.Default value: 0Tuning recommendation: Please set a proper value according to the actual requirement.
- High Threshold
- Description: See “Low Threshold”.Default value: 100Tuning recommendation: Please set a proper value according to the actual requirement.
DynamicThreshold¶
- Thresholding Type
- Description: This parameter determines whether the values of pixels should be set to 255 or 0.Value list: Bright, Dark, In Range, Out of Range. If \(P_o\) is a pixel in the original image, \(P_f\) is the pixel corresponding to \(P_o\) in the filtered image, and \(offset\) is the set value of Pixel Value Offset, then the thresholding types can be explained as follows:
Bright: If \(P_o ≥ P_f + offset\), then \(P_o\) will be set to 255, or else it will be set to 0.
Dark: If \(P_o ≤ P_f - offset\) , then \(P_o\) will be set to 255, or else it will be set to 0.
In Range: If \(P_f - offset ≤ P_o ≤ P_f + offset\) , then \(P_o\) will be set to 255, or else it will be set to 0.
Out of Range: If \(P_o < P_f - offset\) or \(P_o > P_f + offset\), then \(P_o\) will be set to 255, or else it will be set to 0.
- Image Filter
- Description: This parameter is used to select the filter to apply to the image.Value list: Mean filter, Gaussian filter, Median filter
Mean filter: smoothes the image by replacing the center value in the sliding window with the average of all the pixel values in the window.
Gaussian filter: smoothes the image and remove detail and noise.
Median filter: replaces each pixel with the median of neighboring pixels in the window.
Default value: Mean filterTuning recommendation: Please select a proper image filter method according to the actual requirement. - Pixel Value Offset
- Description: The offset pixel value to apply to all pixels of the image after filtering.Default value: 15.00
- Filter Kernel Size
- Description: This parameter sets the sliding window size (pixel-wise edge length) of the filter.Default value: 3Tuning recommendation: Please input an odd number because there should always be a center pixel in the window. Even numbers input will be incremented by one.
Threshold¶
- Threshold (0–255)
- Description: This parameter sets a threshold for filtering image pixels.Default value: 128Tuning recommendation: Please set a proper value according to the actual requirement.
- Operation
- Description: This parameter is used to select the operation type for separating the target object from its background.Value list: THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV, THRESH_OTSU, THRESH_TRIANGLE
THRESH_BINARY: If the original pixel value is above the set threshold, the value will be set to 255, or else it will be set to 0.
THRESH_BINARY_INV: If the original pixel value is above the set threshold, the value will be set to 0, or else it will be set to 255.
THRESH_TRUNC: If the original pixel value is above the set threshold, the value will be set to the same value as the set threshold, or else the original value will be retained.
THRESH_TOZERO: If the original pixel value is above the set threshold, the original value will be retained, or else it will be set to 0.
THRESH_TOZERO_INV: If the original pixel value is above the set threshold, the value will be set to 0, or else the original value will be retained.
THRESH_OTSU: Find a global threshold with the Otsu’s method.
THRESH_TRIANGLE: Find a global threshold with the triangle method.
Default value: THRESH_BINARYTuning recommendation: THRESH_BINARY or THRESH_BINARY_INV is recommended to use.