Image Binarization
Function
This Step is used to binarize pixels based on whether their values are above or below a specified threshold.
|
When the pixel grayscale values in an image have only two possible values (maximum and minimum), i.e., "black or white," such an image is called a binary image. The process of converting a non-binary image into a binary image through calculation is called image binarization. |
Usage Scenario
This Step is generally used for image processing. It is typically applied to segment pixels in 2D images based on a specified threshold.
Parameter Description
| Parameter | Description |
|---|---|
Binary Method |
Parameter description: This parameter specifies the method for image binarization. Value list:
Default value: Adaptive thresholding |
Invert Binary Image |
Parameter description: Select this option to invert the binary result of the entire image: pixels that would be 255 become 0, and pixels that would be 0 become 255.
|
Adaptive Thresholding
The following parameters are available after selecting the Adaptive thresholding method.
| Parameter | Description |
|---|---|
Image Channel Type |
Parameter description: Thresholding is applied based on the selected image channel.
|
Threshold Calculation Method |
Parameter description: This parameter specifies a method for calculating the threshold for each pixel in the image. Value list: Mean, Weighted mean
|
Thresholding Type |
Parameter description: This parameter determines the rule for binarizing the image. Value list: Binary, Binary inverted
|
Kernel Size |
Parameter description: The neighborhood size used during threshold calculation, in pixels (px).
|
Constant |
Parameter description: A constant used for threshold calculation. Increasing this value darkens the output image, while decreasing it brightens the image.
|
Dual Thresholding
The following parameters are available after selecting the Dual thresholding method.
| Parameter | Description |
|---|---|
Threshold 1, Threshold 2 |
Parameter description:
|
Dynamic Thresholding
The following parameters are available after selecting the Dynamic thresholding method.
| Parameter | Description |
|---|---|
Thresholding Type |
Parameter description: This parameter determines the rule for binarizing the image. Let P be the pixel value in the original image, P′ the corresponding pixel value in the filtered image, and offset the set value of Pixel Value Offset. The processing logic of each value in the value list can be described as follows. Value list:
|
Filter Type |
Parameter description: This parameter selects the filter to apply to the image. Value list:
|
Pixel Value Offset |
Parameter description: Adds a constant value to, or subtracts it from, the filtered pixel values to adjust the binarization result. |
Kernel Size |
Parameter description: This parameter sets the filter window size in pixels (px). Please enter an odd number as there should always be a center pixel in the window. Any even numbers entered will be incremented by one. |
Thresholding
The following parameters are available after selecting the Thresholding method.
| Parameter | Description |
|---|---|
Image Channel Type |
Parameter description: Thresholding is applied based on the selected image channel.
|
Threshold (0–255) |
Parameter description: Manually define a fixed global threshold used to segment pixels that meet the threshold condition. |
Thresholding Type |
Parameter description: This parameter determines the rule for binarizing the image. Let P be the pixel value in the original image, P′ the corresponding pixel value in the filtered image, and offset the set value of Pixel Value Offset. The processing logic of each value in the value list can be described as follows. Value list:
|
Parameter Tuning Examples
Case 1: Clean Background with High Target-Background Contrast
-
Scenario:The target object and background have a significant grayscale difference with stable lighting conditions, such as detecting the position of a black object on a white background.
-
Recommended approach: Select the Thresholding method and manually set a fixed threshold for quick and effective separation of the target from the background.
-
Tuning approach:
-
First observe the grayscale histogram of the image to determine the grayscale value ranges of the target and background.
-
Select a value between the two grayscale ranges as the initial threshold (e.g., if the target range is 0–80 and the background range is 150–255, set the initial threshold to 115).
-
Adjust the threshold during the process to progressively optimize the segmentation result.
-
If the target is incompletely segmented, lower the threshold; if there is too much background noise, raise the threshold.
-
Select "Binary" or "Binary inverted" as needed to adjust the foreground and background colors.
-
Case 2: Uneven Lighting with Background Gradient
-
Scenario: In natural lighting environments or scenes with shadows, brightness varies significantly across different regions of the image. Using a global threshold can easily lead to under-segmentation or over-segmentation.
-
Recommended approach: Select the Adaptive thresholding method. The system dynamically calculates the threshold based on the pixel neighborhood, adapting to lighting variations.
-
Tuning approach:
-
Set the initial "Kernel Size" to 21 pixels and observe the segmentation result.
-
If the target contour is blurry or boundary detection is unclear, increase the kernel size (e.g., 31 or 41) to enlarge the neighborhood and make the threshold calculation more stable.
-
If target details are lost, decrease the kernel size (e.g., 11 or 15) to make the threshold more sensitive.
-
Adjust the "Constant" parameter: increasing the constant darkens the overall image (more foreground), while decreasing the constant brightens it (more background).
-
Select the appropriate channel (Grayscale, Hue, Saturation, etc.) based on the image channels to achieve the best segmentation.
-
Case 3: Image Contains Noise, Need to Remove Salt-and-Pepper Noise
-
Scenario: Images acquired by low-quality cameras or in harsh environments contain random black and white noise points (salt-and-pepper noise). Direct binarization would retain the noise.
-
Recommended approach: Select the Dynamic thresholding method combined with Median filtering to effectively remove salt-and-pepper noise.
-
Tuning approach:
-
Select the "Dynamic thresholding" method.
-
Select "Median" as the filter type. Median filtering is particularly suitable for removing salt-and-pepper noise.
-
Set the "Kernel Size" to 5 or 7 (odd number) to define the filter window size.
-
Select the "Thresholding Type" based on the target characteristics:
-
To detect brighter targets, select "Bright region".
-
To detect darker targets, select "Dark region".
-
To detect pixels within a certain range, select "In range".
-
To detect pixels outside a certain range, select "Out of range".
-
-
Adjust the "Pixel Value Offset" (offset) to control the segmentation tolerance: increasing the offset includes more pixels, while decreasing it makes the segmentation stricter.
-
Observe the result and progressively fine-tune the kernel size and offset value.
-
Case 4: Need to Extract a Specific Brightness Range
-
Scenario: The target object’s grayscale values are concentrated in a specific range, and pixels within this range need to be precisely extracted, such as detecting regions of specific brightness on a semiconductor chip surface.
-
Recommended approach: Select the Dual thresholding method to precisely control the pixel range by setting two threshold boundaries.
-
Tuning approach:
-
Observe the grayscale value range of the target region, e.g., target pixel grayscale is 100–180.
-
Set Threshold 1 to the lower bound and Threshold 2 to the upper bound of the range (e.g., Threshold 1 = 100, Threshold 2 = 180).
-
This extracts pixels between the two thresholds as 255, and all other pixels as 0.
-
If reverse extraction is needed (extracting pixels outside the range), adjust Threshold 1 and Threshold 2 so that Threshold 1 > Threshold 2.
-
Progressively adjust the boundary values of both thresholds based on the segmentation result to achieve precise grayscale range filtering.
-