An adaptive threshold-based industrial part binarization segmentation method

CN122737162APending Publication Date: 2026-09-11JIANGYIN FEIXIN ARTIFICIAL INTELLIGENCE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610847092.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-12
Publication Date
2026-09-11

AI Technical Summary

Technical Problem

其一,传统的固定阈值二值化方法需要针对每类工件和每种光照条件手动设定阈值——一旦光照条件变化如车间照明灯管老化变暗或新增补光灯后亮度提升或更换工件类型如从锁销切换到不同材质的紧固件,固定阈值将导致分割失败,表现为前景遗漏或背景误分割,这是因为全局灰度值整体偏移后原有阈值不再对应前/背景之间的灰度分界点

Benefits of technology

[0013]This invention offers the following advantages: First, it automatically calculates the globally optimal threshold using the OTSU algorithm, with the threshold determined entirely by the statistical characteristics of the grayscale distribution of the input image, eliminating the need for manual setting. Second, the OTSU algorithm is a global thresholding method, avoiding the sensitivity issues associated with local window parameters. Third, the combined post-processing of morphological closing operations and connected component area filtering compensates for the connectivity defects in the initial OTSU segmentation results. Quantitative testing shows that within a global illumination shift of ±15 grayscale levels, the segmentation F1 score remains stable above 0.96, representing a 33% improvement compared to the fixed threshold method, which increases the F1 score from 0.72 to 0.96 under varying illumination conditions. The morphological closing operation using a 5×5 rectangular kernel takes 8ms to process a 640×480 resolution image. Area filtering can remove noise points with an area smaller than 200 pixels, achieving a foreground extraction accuracy of 98.5%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122737162A_ABST
    Figure CN122737162A_ABST
Patent Text Reader

Abstract

This invention discloses a binarization segmentation method for industrial parts based on adaptive thresholding, belonging to the field of industrial machine vision image segmentation technology. The method includes: performing grayscale histogram statistics on the input ROI grayscale image and automatically calculating the optimal binarization threshold using the OTSU algorithm; performing global binarization with this threshold to obtain a preliminary binary image; filling foreground holes and bridging boundary breaks through morphological closing operations; performing connected component analysis on the closing operation results and selecting the connected component with the largest area as the foreground of the target part. This method determines the threshold entirely by the statistical characteristics of the image's grayscale distribution, requiring no manual parameter tuning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial machine vision image segmentation technology, specifically to a binarization segmentation method for industrial parts based on adaptive thresholding. Background Technology

[0002] The existing technical solutions have the following shortcomings: Firstly, the traditional fixed threshold binarization method requires manually setting the threshold for each type of workpiece and each lighting condition. Once the lighting conditions change, such as the workshop lighting tubes aging and dimming, or the brightness increasing after the addition of supplementary lighting, or the type of workpiece is changed, such as switching from locking pins to fasteners of different materials, the fixed threshold will cause the segmentation to fail, resulting in the omission of the foreground or the missegmentation of the background. This is because after the global grayscale value shifts as a whole, the original threshold no longer corresponds to the grayscale boundary point between the foreground and the background.

[0003] Secondly, while adaptive thresholding methods, such as local adaptive thresholding, can adapt to changes in lighting to some extent, the choice of local window size is sensitive to the segmentation effect. If the window is too large, it loses its "adaptive" meaning and degenerates into a near-global threshold. If the window is too small, it will produce a large number of artifacts in areas with complex textures. This parameter sensitivity means that adaptive thresholding methods need to be repeatedly debugged when migrating between different workpiece types.

[0004] Third, the binarization result obtained by directly applying the OTSU algorithm can have holes and boundary breaks in the foreground region. This is because the texture and shadow of the workpiece surface itself will be mistakenly classified as background under the OTSU threshold. Furthermore, the OTSU algorithm does not include any morphological post-processing steps, and the output binary mask has defects in foreground connectivity.

[0005] Firstly, addressing the first shortcoming of the background technology, the OTSU algorithm automatically calculates the globally optimal threshold—based on the gray-level histogram's inter-class variance maximization criterion. The threshold is entirely determined by the statistical characteristics of the input image's gray-level distribution, eliminating the need for manually setting any fixed threshold value. This removes the dependence on operational experience and the inability to adapt to changes in illumination caused by manually setting fixed thresholds. OTSU is based on the bimodal histogram assumption, which naturally matches the actual gray-level distribution characteristics of industrial parts imaged against a uniformly illuminated disk background. This is not simply "changing the thresholding algorithm."

[0006] Secondly, in response to the second defect of the background technology, the OTSU algorithm is a global thresholding method that does not introduce local window parameters. Therefore, there is no parameter sensitivity problem caused by window size selection. When the overall illumination shifts, such as when the lamp aging causes the entire image to darken, the OTSU threshold automatically tracks the corresponding shift of the valley position between the two peaks of the histogram, realizing automatic adaptation to illumination changes without producing local artifacts.

[0007] Thirdly, in response to the third defect of the background technology, the internal holes and boundary breaks in the initial OTSU segmentation result are filled by morphological closing operations, and noise connected regions are removed by connected region area filtering. This three-stage pipeline of "OTSU initial segmentation + morphological repair + area filtering" is not a simple chain of independent algorithms, but a targeted compensation for the defects of OTSU output: closing operations restore topological integrity, area filtering removes scattered noise, and the final output binary mask contains only the complete foreground region of a single target part. Summary of the Invention

[0008] The purpose of this invention is to provide an adaptive threshold-based binarization segmentation method for industrial parts. The method uses the OTSU algorithm to automatically calculate the globally optimal binarization threshold for initial segmentation, and combines morphological closing operations and connected component filtering to perform post-processing optimization on the segmentation results, so as to achieve an adaptive segmentation scheme that is robust to different workpieces and lighting conditions without the need for manual parameter tuning.

[0009] An adaptive threshold-based binarization segmentation method for industrial parts includes at least the following steps: Step 1: Perform grayscale histogram statistics on the input ROI grayscale image, and use the OTSU algorithm to automatically calculate the optimal binarization threshold based on the maximization of inter-class variance criterion.

[0010] Step 2: Using the optimal binarization threshold as the segmentation boundary, perform a global binarization operation on the grayscale image. Pixels with grayscale values ​​greater than the threshold are set to white, and pixels with grayscale values ​​less than or equal to the threshold are set to black, thus obtaining a preliminary binarized image.

[0011] Step 3: Perform morphological closing operation on the preliminary binarized image, using a structuring element of a specified size to first dilate and then erode, filling small holes inside the foreground region and bridging narrow fracture areas.

[0012] Step 4: Perform connected component analysis on the binary image after the closing operation, extract all connected components and calculate the area of ​​each connected component, select the connected component with the largest area as the foreground of the target part, and filter out small-area noise connected components with an area smaller than a specified threshold.

[0013] This invention offers the following advantages: First, it automatically calculates the globally optimal threshold using the OTSU algorithm, with the threshold determined entirely by the statistical characteristics of the grayscale distribution of the input image, eliminating the need for manual setting. Second, the OTSU algorithm is a global thresholding method, avoiding the sensitivity issues associated with local window parameters. Third, the combined post-processing of morphological closing operations and connected component area filtering compensates for the connectivity defects in the initial OTSU segmentation results. Quantitative testing shows that within a global illumination shift of ±15 grayscale levels, the segmentation F1 score remains stable above 0.96, representing a 33% improvement compared to the fixed threshold method, which increases the F1 score from 0.72 to 0.96 under varying illumination conditions. The morphological closing operation using a 5×5 rectangular kernel takes 8ms to process a 640×480 resolution image. Area filtering can remove noise points with an area smaller than 200 pixels, achieving a foreground extraction accuracy of 98.5%. Attached Figure Description

[0014] Figure 1 This is the overall flowchart of the industrial parts binarization segmentation method based on adaptive threshold in this invention.

[0015] Figure 2 This is a schematic diagram of the grayscale histogram and the OTSU threshold position in this invention.

[0016] Figure 3 This is a schematic diagram comparing the binarization segmentation before and after in this invention. The meanings of the markings in the diagram are as follows: Figure 1 In the middle section: 100 - Gray-level histogram statistics and OTSU threshold calculation steps, 101 - Global binarization operation steps, 102 - Morphological closing operation processing steps, 103 - Connected component analysis and area filtering steps, 104 - Output segmentation results steps.

[0017] Figure 2 In the middle: 200 - the optimal threshold boundary calculated by the OTSU algorithm, 201 - the gray value peak of the background region, and 202 - the gray value peak of the foreground region.

[0018] Figure 3 In the middle: 300 - Original grayscale image region, 301 - OTSU binarization segmentation processing module, 302 - Target part foreground connected region, 303 - Target part foreground connected region. Detailed Implementation

[0019] This invention is applied to the industrial machine vision image segmentation process, running on the robot's end-side processor, as a preprocessing step in the part inspection chain.

[0020] In step one, as Figure 1 Mark 100 and Figure 2As shown, grayscale histogram statistics are performed on a ROI grayscale image with an input resolution of 640×480. The OTSU algorithm traverses 256 grayscale levels from 0 to 255, calculating the pixel ratio of foreground and background, the average grayscale value, and further calculating the inter-class variance for each candidate threshold. The grayscale level that maximizes the inter-class variance is selected as the optimal binarization threshold, which is located at the valley between the two peaks of the histogram. Figure 2 As shown in the middle (marked 200). The OTSU threshold calculation took 5ms on a 640×480 image.

[0021] In step two, as Figure 1 As shown in the diagram marked 101, a global binarization operation is performed using the optimal OTSU threshold obtained in step one as the segmentation boundary. Pixels with grayscale values ​​greater than the threshold are set to white, and pixels with grayscale values ​​not greater than the threshold are set to black, resulting in a preliminary binarized image. Global binarization is a pixel-by-pixel independent operation, taking 2ms on a 640×480 image.

[0022] In step three, as Figure 1 As shown in mark 102, a morphological closing operation is performed on the initially binarized image. Using a 5×5 pixel rectangular structuring element, a dilation operation is first performed to fill small holes with a diameter of less than 5 pixels inside the foreground region, and then an erosion operation is performed to restore the boundary accuracy of the target region. The closing operation bridges narrow fracture regions with a width of less than 5 pixels, and the processing time is 8ms.

[0023] In step four, as Figure 1 As shown in marker 103, the 8-adjacent connected component labeling algorithm is used to perform connected component analysis on the binary image after the closing operation. All connected components are extracted and their areas are calculated. Small-area noise connected components with an area less than 200 pixels are filtered out. The connected component with the largest area from the remaining connected components is selected as the foreground output of the target part. Figure 1 As shown in marker 104. Connectivity analysis takes 10ms on a 640×480 resolution image, with a total processing time of 25ms, meeting the 30fps real-time processing requirement.

Claims

1. An adaptive threshold based industrial part binarization segmentation method, characterized in that, The method includes at least the following steps: Step 1, performing grayscale histogram statistics on the input ROI grayscale image and automatically calculating the optimal binarization threshold using the OTSU algorithm based on the maximization of inter-class variance criterion; Step 2, performing global binarization operation with the optimal binarization threshold as the segmentation boundary to obtain a preliminary binarized image; Step 3, performing morphological closing operation on the preliminary binarized image, using structuring elements of a specified size to fill small holes inside the foreground region and repair narrow breaks; Step 4, performing connected component analysis on the binarized image after closing operation, extracting all connected components and calculating the area of ​​each connected component, and selecting the connected component with the largest area as the foreground of the target part; the method is executed by the robot end-side processor.

2. The method of claim 1, wherein, The structuring element of the morphological closing operation in step three is a rectangular kernel of a specified size, which is first expanded and then eroded.

3. The method of claim 1, wherein, The connected component analysis in step four uses an 8-adjacent connected component labeling algorithm to filter out connected components with an area smaller than a specified threshold.

4. The method of claim 1, wherein, The OTSU algorithm described in step one iterates through all gray levels from 0 to 255, calculates the inter-class variance when each gray level is used as a threshold, and selects the gray level that maximizes the inter-class variance as the optimal binarization threshold.

5. An adaptive threshold based industrial part binarization segmentation system, comprising: include: A threshold calculation module for performing grayscale histogram statistics on the input ROI grayscale image and automatically calculating the optimal binarization threshold using the OTSU algorithm; A global binarization module for performing global binarization with the optimal binarization threshold as the segmentation boundary to obtain a preliminary binarized image; A morphological restoration module for performing morphological closing operations on a pre-binarized image to fill foreground holes and repair boundary breaks. This module is used to perform connected component analysis on binary images after closing operations and to filter connected components with the largest area.

6. The system of claim 5, wherein, The structural element in the morphological repair module is a rectangular core of a specified size, which is first expanded and then eroded.

7. The system according to claim 5, characterized in that, The connected component filtering module uses an 8-adjacent connected component labeling algorithm to filter out connected components with an area smaller than a specified threshold.

8. The system according to claim 5, characterized in that, In the threshold calculation module, the OTSU algorithm iterates through all gray levels from 0 to 255 to calculate the inter-class variance.

9. A robotic device, characterized in that, Includes the system as described in any one of claims 5 to 8.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 4.