A weld segmentation algorithm for radiographic images based on iterative threshold
Through the combination of the iterative threshold method and the termination condition of the centroid distance difference, the segmentation problem caused by low edge contrast in the weld area in the ray image is solved, achieving more accurate weld segmentation and reducing data annotation workload.
Patent Information
- Application Number
- CN202310093158.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-10
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2043-02-10
AI Technical Summary
The existing ray image weld segmentation algorithm is prone to excessive segmentation or missing segmentation when the edge contrast of the weld area is low, and requires a lot of preliminary data annotation work.
The ray image weld segmentation algorithm based on iteration threshold is used, and image pre-processing is performed through grayscale stretching and median filtering, and weld segmentation is performed by combining histogram equalization and iterative threshold method, and the optimal threshold is gradually approached by the difference in the centroid distance as the cycle termination condition.
It effectively solves the problem of excessive segmentation caused by low boundary contrast in the weld area, improves the segmentation accuracy of the weld area, and reduces the workload of data labeling.
Smart Images

Figure CN115984249B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of pipeline weld defect recognition technology and machine learning technology, and in particular to a radiographic image weld segmentation algorithm based on iterative threshold. Background Art
[0002] When transporting natural gas through pipelines, leaks can cause serious losses. Therefore, pipeline quality inspections, particularly at welds, are essential before commissioning. To more effectively identify defects in welds, defect recognition methods are beginning to incorporate artificial intelligence (AI) to automatically identify defects in pipeline X-ray inspection images. However, raw radiographic images contain a significant amount of information unrelated to the defects, with the weld area representing only about one-third of the image size. Therefore, using segmentation algorithms to pre-segment the weld area facilitates defect identification.
[0003] Zhang Xiaoguang et al. (Zhang Xiaoguang, Sun Zheng, Hu Xiaolei, et al. Method for extracting welds and defects from radiographic inspection images [J]. Transactions of the China Welding Institution, 2011, 32(2):77-80, 117.) used a rectangular window to move from the center of the image to both sides and determined the weld area by comparing the average brightness and consistency. Qi Jiyang et al. (Qi Jiyang, Li Jinyan, Lu Zhenyun, et al. Application of improved Otsu method in welding image segmentation [J]. Transactions of the China Welding Institution, 2016, 37(10):97-100.) considered the experimental results of two improved algorithms in the maximum inter-class variance method (using the ratio of intra-class variance to inter-class variance instead of inter-class variance and using variance information instead of mean information in the original algorithm) and jointly segmented the weld area. Oto Haffner et al. (Haffner O, KUCERA E, DRAHOS P, et al. Using entropy for welds segmentation and evaluation [J]. Entropy, 2019, 21(12): 1168.) calculated the local entropy within the 8-neighborhood range of the central pixel, used the local entropy instead of the central pixel value, and performed image weld segmentation on the local entropy matrix. Su Jinan et al. (Su Jinan, Chen Xubing, Dai Yaonan. Research on weld image edge extraction in noisy environment [J]. Computer Application Research, 2020, 37(S1): 368-369+384.) improved the morphological edge extraction operator and extracted the weld edge from the image under the influence of Gaussian and salt and pepper noise. Peng Daogang et al. (Peng Daogang, Yin Lei, Qi Erjiang, et al. Power plant pipeline defect detection and segmentation based on OTSU and region growing [J]. Infrared Technology, 2021, 43(05): 502-509.) used the grayscale image and its 3x3 neighborhood smoothed image to obtain the joint probability density, and used the probability density to improve the maximum inter-class variance method to extract the weld part. Dai Xuanling et al. (Dai Xuanling, Mao Yunsheng, Zhou Yongqing. Weld segmentation algorithm based on improved watershed [J]. Ship Engineering, 2021, 43(S1): 428-433.) First, the weld image was preprocessed using background correction and maximum inter-class variance method, and then the corrosion, expansion and watershed algorithms were used to segment the weld, and the particles were marked. Finally, the weld was extracted according to the particle area. Wang Lihui et al. (WANG LH, SHEN Q C. Visual inspection of welding zone by boundary-aware semantic segmentation algorithm[J]. IEEE Transactions on Instrumentation and Measurement, 2021, 70: 1-9.) used a boundary-aware semantic segmentation algorithm to extract the boundary information of the water-cooling pipe.However, because weld edges in flaw detection images have low contrast and low grayscale values, threshold segmentation algorithms can suffer from over-segmentation (the extracted area includes some background) and under-segmentation (the extracted area misses the weld edge). This invention uses histogram equalization to enhance image contrast and increases the threshold in fixed steps to approach the optimal segmentation threshold. Furthermore, this method uses threshold segmentation, eliminating the need for a training process like semantic segmentation algorithms, reducing the workload of pre-process data annotation. Summary of the Invention
[0004] The present invention mainly overcomes the deficiencies in the prior art and provides a radiographic image weld segmentation algorithm based on an iterative threshold.
[0005] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:
[0006] 1. A radiographic weld segmentation algorithm based on iterative threshold, characterized by comprising the following steps:
[0007] Step 1: Use grayscale stretching and median filtering to preprocess the original image to obtain the preprocessed image. The grayscale stretching formula is:
[0008]
[0009] Among them, g is the pixel value after grayscale stretching, and its value range is [0, g max ], g max is the maximum pixel value of the stretched image, the value range is a positive integer, and g max Greater than f max , f is the pixel value of the original image, f max is the maximum pixel value of the original image, f min is the minimum pixel value of the original image, To round down, the median filter uses the median of all pixel values within the m×n window size of the original pixel value to replace the original pixel value, and the value ranges of m and n are both positive integers;
[0010] Step 2: Use the output of step 1 as the input image, perform histogram equalization on the input image, increase the pixel values of the weld area and its boundaries, and output the equalized image. The histogram equalization formula is:
[0011]
[0012] Among them, s is the pixel value after equalization, and its value range is [0,s max ], s max is the maximum pixel value of the equalized image, and its value range is a positive integer. N is the total number of pixels in the input image, and nj is the total number of pixels in the input image whose pixel value is equal to j;
[0013] Step 3: Use the output of step 2 as the input image and use the iterative threshold method to segment the weld. Modify the iterative threshold in terms of threshold update method and loop termination condition. The specific implementation steps are as follows:
[0014] (1) Initialize the variables of the iterative threshold method, including the initial threshold t0, the fixed step size of the loop, and the termination condition value ε, where the value range of t0 is the interval [0, w max ], w max is the maximum pixel value of the input image, and the value range of step is [1,w max ], the value range of ε is a positive number;
[0015] (2) The output of step 2 is used as the input image, and the input image is binarized using the initial threshold t0. The binarization operation is as follows: if the pixel value of the image pixel is greater than or equal to the threshold, the pixel value of the pixel becomes 1, otherwise the pixel value becomes 0. The result of binarization is a binary image;
[0016] (3) Take the binary image output in (2) as the input image, calculate the centroid coordinates of the largest connected area in the input image, then calculate the centroid coordinates of the minimum circumscribed rectangle of the largest connected area, and then calculate the distance between the two centroid coordinates to obtain the centroid distance. If there are any two pixel points A and B in the binary image, their pixel values are both equal to 1, and A is within the m×n window size centered on B, and the value ranges of m and n are both positive integers, then A and B are connected. The largest connected area is the area with the largest number of connected pixels in the binary image. The formula for the centroid distance is:
[0017]
[0018] Among them, X con Indicates the row coordinates of the centroid of the largest connected region, which is the mean of the row coordinates of all pixels in the largest connected region. rec Indicates the row coordinates of the centroid of the bounding rectangle, which is the mean of the row coordinates of all pixels in the bounding rectangle. con The column coordinates of the centroid of the largest connected region are taken as the mean of the column coordinates of all pixels in the largest connected region. rec The column coordinates of the centroid of the bounding rectangle are equal to the mean of the column coordinates of all pixels in the bounding rectangle.
[0019] (4) Add the fixed step size step to the initial threshold value t0 to obtain the threshold value t1 of the first cycle. Use this threshold to binarize the input image and calculate the center of mass distance of the first cycle. Then subtract the center of mass distance of the first cycle from the center of mass distance obtained in (3) to obtain their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold value t1 is used as the final threshold value. Otherwise, proceed to step (5); (5) Add the fixed step size step to the threshold value of the previous cycle to obtain the threshold value t of the kth cycle. k , multiply the input of the previous cycle by the template as the input of the kth cycle, where the template is obtained by changing the pixel values of the pixels outside the largest connected area in the binary image of the previous cycle to 0, and obtaining the template using the threshold t k Binarize the input, calculate the centroid distance of this cycle, and then subtract the centroid distance of this cycle from the centroid distance of the previous cycle to get their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold t is set. k As the final threshold, otherwise, repeat step (5) until the difference is greater than the termination condition value ε. The conditional formula for the termination of the loop is:
[0020] Δd>ε
[0021] Among them, Δd is the difference between the center-of-mass distance of the previous cycle and the center-of-mass distance of the current cycle, and the formula is:
[0022] Δd=d k-1 -d k
[0023] Among them, k is the number of cycles, and its value range is an integer in the interval [1, +∞), d k is the center of mass distance of the kth cycle, the kth cycle is the current cycle, d k-1 is the centroid distance of the k-1th cycle. The calculation formula of the centroid distance is the same as that in step (5);
[0024] (6) The input is binarized using the final threshold, and then the minimum row coordinate and the maximum row coordinate of the largest connected area in the binary image are calculated. The weld area is segmented from the original image based on these two coordinates.
[0025] The present invention provides an algorithm for weld segmentation of radiographic images based on iterative thresholds. The algorithm is modified in terms of threshold update method and loop termination condition. In the original iterative threshold method, the threshold update method is to calculate the average pixel value of the foreground and the average pixel value of the background respectively, and use their average as the threshold of the next cycle. The loop termination condition is that the difference between the thresholds of the two cycles is very small or unchanged. The threshold of the present invention is updated according to a fixed step size, and the threshold of the current iteration is increased upward according to a fixed step size based on the threshold of the previous iteration, gradually approaching the optimal segmentation threshold; the loop termination condition is that the termination judgment formula is greater than a preset value, wherein the termination judgment formula is the difference between the distance between the centroid of the maximum connected area and the centroid of its minimum circumscribed rectangle in the binary image of the current cycle and the centroid distance in the previous cycle. Compared with the Otsu threshold method, the Otsu threshold method uses the inter-class variance of the foreground and background as the threshold screening condition, while the present invention uses the distance difference between the two cycles as the judgment condition, which is more suitable for the situation where the weld is horizontally distributed in the image, and is conducive to the segmentation of the weld area.
[0026] Beneficial effects:
[0027] Compared with the prior art, the present invention has the following beneficial effects:
[0028] Using a fixed step size to increase the threshold in the loop can make the threshold gradually approach the optimal threshold and eventually stop near the optimal threshold, which can better solve the over-segmentation problem caused by low contrast at the weld area boundary; using the difference in centroid distance as the judgment formula for loop termination is more suitable for the horizontal rectangular distribution of the weld, and can effectively capture the changes in the separation between the weld boundary and the surrounding pixels, so that the segmentation result can better separate the weld from the pipe wall. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a flow chart for weld defect recognition, which consists of six parts: original image, image preprocessing, histogram equalization, the algorithm of the present invention, defect classification, and classification results. It represents the processing flow of the defect classification task in radiographic images, and the present invention is located in the center of the process, playing an important auxiliary role in the defect classification task.
[0030] Figure 2 It is a flowchart of the traditional iterative threshold segmentation algorithm, which shows the process of welding seam segmentation by the traditional iterative threshold method.
[0031] Figure 3 It is a flow chart of a radiographic image weld segmentation algorithm based on iterative threshold, which shows the process from the initial threshold to the final threshold of the present invention;
[0032] Figure 4 This is an example of weld area segmentation. The image above the arrow is the input image, and the image below the arrow is the final segmented weld area. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0034] Example:
[0035] A radiographic weld segmentation algorithm based on iterative threshold is specifically implemented as follows:
[0036] Step 1: Use grayscale stretching and median filtering to preprocess the original image to obtain the preprocessed image. The grayscale stretching formula is:
[0037]
[0038] Among them, g is the pixel value after grayscale stretching, g max is the maximum pixel value of the stretched image, which is 255. max is the maximum pixel value of the original image, f min is the minimum pixel value of the original image, To round down, the median filter window size is selected as 3x3;
[0039] Step 2: Use the output of step 1 as the input image, perform histogram equalization on the input image, increase the pixel values of the weld area and its boundaries, and output the equalized image. The histogram equalization formula is:
[0040]
[0041] Among them, s is the pixel value after equalization, s max is the maximum pixel value of the equalized image, which is 255. N is the total number of pixels in the input image. j is the total number of pixels in the input image whose pixel value is equal to j;
[0042] Step 3: Use the output of step 2 as the input image and use the iterative threshold method to segment the weld. Modify the iterative threshold in terms of threshold update method and loop termination condition. The specific implementation steps are as follows:
[0043] (1) Initialize the variables of the iterative threshold method so that the fixed step length of the loop is step = 10, the termination condition value ε = 100, and the initial threshold t0 is selected from the median, mean and Otsu threshold, and compare them in the experiment;
[0044] (2) Take the output of step 2 as the input image and use the initial threshold t0 to binarize the input image to obtain a binary image;
[0045] (3) Using the binary image output in (2) as the input image, calculate the centroid coordinates of the largest connected region in the input image, then calculate the centroid coordinates of the minimum circumscribed rectangle of the largest connected region, and then calculate the distance between the two centroid coordinates to obtain the centroid distance;
[0046] (4) Add the fixed step size step to the initial threshold t0 to obtain the threshold t1 of the first cycle. Use this threshold to binarize the input image and calculate the center of mass distance of the first cycle. Then subtract the center of mass distance of the first cycle from the center of mass distance obtained in (3) to obtain their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold t1 is used as the final threshold. Otherwise, proceed to step (5).
[0047] (5) Add the fixed step size step to the threshold of the previous cycle to obtain the threshold t of the kth cycle k , multiply the input of the previous cycle by the template as the input of the kth cycle, where the template is obtained by changing the pixel values of the pixels outside the largest connected area in the binary image of the previous cycle to 0, and obtaining the template using the threshold t k Binarize the input, calculate the centroid distance of this cycle, and then subtract the centroid distance of this cycle from the centroid distance of the previous cycle to get their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold t is set. k As the final threshold, otherwise, repeat step (5) until the difference is greater than the termination condition value ε. The conditional formula for the termination of the loop is:
[0048] Δd>ε
[0049] Among them, Δd is the difference between the center-of-mass distance of the previous cycle and the center-of-mass distance of the current cycle, and the formula is:
[0050] Δd=d k-1 -d k
[0051] Among them, k is the number of cycles, d k is the center of mass distance of the kth cycle, the kth cycle is the current cycle, d k-1 is the centroid distance of the k-1th cycle. The calculation formula of the centroid distance is the same as that in step (5);
[0052] (6) Binarize the input using the final threshold, then calculate the minimum row coordinate and the maximum row coordinate of the largest connected area in the binary image, and segment the weld area from the original image based on these two coordinates;
[0053] Step 4: Manually mark the weld areas of all images in the dataset with rectangular boxes to obtain the actual weld areas of all images. The dataset consists of 375 pipeline weld radiographic images. The average intersection-over-union (IoU) is used to evaluate the degree of overlap between the weld areas segmented by different algorithms and the actual weld areas. The average IoU is the average of the IoU ratios of the weld areas segmented by the algorithms and the actual weld areas in all images. The formula for IoU is:
[0054]
[0055] Among them, IOU is the intersection-union ratio, box p The weld area segmented by the algorithm, box t is the actual weld area, ∩ and ∪ are intersection and union operations, and the accuracy rate is used to evaluate the correct number of weld areas segmented by different algorithms in the data set. The accuracy rate is the ratio of the number of images with correct welds segmented in the data set, wherein the intersection ratio threshold T is set, and the value range is the interval [0,1]. If the intersection ratio of the segmented weld area and the actual weld area is greater than T, it means that the segmented weld is correct. Here, the value of T is set to 0.5. The segmentation effects of different algorithms are compared using the above evaluation method, including the maximum inter-class variance method, the entropy-based weld segmentation algorithm, the improved watershed segmentation algorithm and the algorithm of the present invention (wherein the maximum inter-class variance method is the model of the literature (Otsu NA threshold selection method from gray-level histograms [J]. Automatica, 1975, 11 (23): 285-296.), and the entropy-based weld segmentation algorithm is the literature (Haffner O, Kucera E, Drahos P, et al. Using entropy for welds segmentation andevaluation[J].Entropy,2019,21(12):1168.), the improved watershed segmentation algorithm is the model of the literature (Dai Xuanling, Mao Yunsheng, Zhou Yongqing. Weld segmentation algorithm based on improved watershed[J]. Ship Engineering, 2021,43(S1):428-433.), the algorithm of the present invention is divided into three cases: the initial threshold is the median, mean and Otsu threshold), and the comparison results are shown in Table 1.
[0056] Table 1 Average intersection-to-union ratios of different algorithms
[0057]
[0058] The above description does not limit the present invention in any form. Although the present invention has been disclosed through the above embodiments, it is not intended to limit the present invention. Any technician familiar with the profession can use the technical content disclosed above to make changes or modifications to equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the technical solution of the present invention.
Claims
1. A radiographic weld segmentation algorithm based on iterative threshold, characterized by The following steps are involved: Step 1: Use grayscale stretching and median filtering to preprocess the original image to obtain the preprocessed image. The grayscale stretching formula is: Among them, g is the pixel value after grayscale stretching, and its value range is [0, g max ], g max is the maximum pixel value of the stretched image, the value range is a positive integer, and g max Greater than f max , f is the pixel value of the original image, f max is the maximum pixel value of the original image, f min is the minimum pixel value of the original image, To round down, the median filter uses the median of all pixel values within the m×n window size of the original pixel value to replace the original pixel value, and the value ranges of m and n are both positive integers; Step 2: Use the output of step 1 as the input image, perform histogram equalization on the input image, increase the pixel values of the weld area and its boundaries, and output the equalized image. The histogram equalization formula is: Among them, s is the pixel value after equalization, and its value range is [0,s max ], s max is the maximum pixel value of the equalized image, and its value range is a positive integer. N is the total number of pixels in the input image, and n j is the total number of pixels in the input image whose pixel value is equal to j; Step 3: Use the output of step 2 as the input image and use the iterative threshold method to segment the weld. Modify the iterative threshold in terms of threshold update method and loop termination condition. The specific implementation steps are as follows: (1) Initialize the variables of the iterative threshold method, including the initial threshold t0, the fixed step size of the loop, and the termination condition value ε, where the value range of t0 is the interval [0, w max ], w max is the maximum pixel value of the input image, and the value range of step is [1,w max ], the value range of ε is a positive number; (2) The output of step 2 is used as the input image, and the input image is binarized using the initial threshold t0. The binarization operation is as follows: if the pixel value of the image pixel is greater than or equal to the threshold, the pixel value of the pixel becomes 1, otherwise the pixel value becomes 0. The result of binarization is a binary image; (3) Take the binary image output in (2) as the input image, calculate the centroid coordinates of the largest connected area in the input image, then calculate the centroid coordinates of the minimum circumscribed rectangle of the largest connected area, and then calculate the distance between the two centroid coordinates to obtain the centroid distance. If there are any two pixel points A and B in the binary image, their pixel values are both equal to 1, and A is within the m×n window size centered on B, and the value ranges of m and n are both positive integers, then A and B are connected. The largest connected area is the area with the largest number of connected pixels in the binary image. The formula for the centroid distance is: Among them, X con Indicates the row coordinates of the centroid of the largest connected region, which is the mean of the row coordinates of all pixels in the largest connected region. rec Indicates the row coordinates of the centroid of the bounding rectangle, which is the mean of the row coordinates of all pixels in the bounding rectangle. con The column coordinates of the centroid of the largest connected region are taken as the mean of the column coordinates of all pixels in the largest connected region. rec The column coordinates of the centroid of the bounding rectangle are equal to the mean of the column coordinates of all pixels in the bounding rectangle. (4) Add the fixed step size step to the initial threshold t0 to obtain the threshold t1 of the first cycle. Use this threshold to binarize the input image and calculate the center of mass distance of the first cycle. Then subtract the center of mass distance of the first cycle from the center of mass distance obtained in (3) to obtain their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold t1 is used as the final threshold. Otherwise, proceed to step (5). (5) Add the fixed step size step to the threshold of the previous cycle to obtain the threshold t of the kth cycle k , multiply the input of the previous cycle by the template as the input of the kth cycle, where the template is obtained by changing the pixel values of the pixels outside the largest connected area in the binary image of the previous cycle to 0, and obtaining the template using the threshold t k Binarize the input, calculate the centroid distance of this cycle, and then subtract the centroid distance of this cycle from the centroid distance of the previous cycle to get their difference. If the difference is greater than the termination condition value ε, the cycle terminates and the threshold t is set. k As the final threshold, otherwise, repeat step (5) until the difference is greater than the termination condition value ε. The conditional formula for the termination of the loop is: Δd>ε Among them, Δd is the difference between the center-of-mass distance of the previous cycle and the center-of-mass distance of the current cycle, and the formula is: Δd=d k-1 -d k Among them, k is the number of cycles, and its value range is an integer in the interval [1, +∞), d k is the center of mass distance of the kth cycle, the kth cycle is the current cycle, d k-1 is the centroid distance of the k-1th cycle. The calculation formula of the centroid distance is the same as that in step (5); (6) The input is binarized using the final threshold, and then the minimum row coordinate and the maximum row coordinate of the largest connected area in the binary image are calculated. The weld area is segmented from the original image based on these two coordinates.
Citation Information
Patent Citations
3D Otsu threshold segmentation method based on iteration and dimensionality decomposition
CN114066923A
Methods, systems, and computer programs for segmenting a tooth's pulp region from an image
US20210209764A1