An Image Segmentation Threshold Calculation Method Based on Brightness-Weighted Maximum Inter-Class Variance

By introducing threshold weighting coefficients into the OTSU algorithm, combining the functional relationship between image brightness and threshold, the segmentation misjudgment problem of OTSU algorithm at low brightness is solved, and the accuracy and effect of image segmentation are improved.

CN115797383BActive Publication Date: 2025-07-25SHANDONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211445310.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-18
Publication Date
2025-07-25
Estimated Expiration
2042-11-18

AI Technical Summary

Technical Problem

The OTSU algorithm easily misjudged the impurities in the image as foreground under low brightness, resulting in segmentation errors.

Method used

The threshold weighting coefficient is introduced, and the functional relationship between the brightness of the image sample and the threshold weighting coefficient is obtained, and the final image segmentation threshold is calculated based on the maximum inter-class variance method to improve the segmentation effect.

Benefits of technology

It improves the segmentation accuracy of the OTSU algorithm under low brightness conditions, effectively distinguishes the foreground from impurities, and improves the segmentation effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115797383B_ABST
    Figure CN115797383B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of image processing, and discloses an image segmentation threshold calculation method based on luminance weighted between-class variance, which includes the following steps: obtaining the functional relationship between the threshold weighting coefficient and the image luminance from an image sample; calculating the luminance of the image to be segmented, calculating the threshold weighting coefficient according to the obtained functional relationship, and performing amplitude limiting; counting the number of pixels corresponding to each gray level of the image to be segmented to obtain the gray level distribution of the image, and obtaining the gray level value corresponding to the foreground peak of the gray level distribution of the image through a loop comparison method; using the between-class variance method to find the maximum between-class variance threshold; calculating the final image segmentation threshold by using the amplitude-limited threshold weighting coefficient, gray level value, and maximum between-class variance threshold. The method disclosed by the present invention introduces a threshold weighting coefficient, which can effectively improve the segmentation accuracy and improve the segmentation effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and particularly relates to a method for calculating an image segmentation threshold based on brightness-weighted maximum inter-class variance. Background Art

[0002] Image segmentation divides an image into different connected regions according to the characteristics of the image, so that the pixel points within the region satisfy the consistency of a specific region. Currently, mainstream image segmentation algorithms can be roughly divided into three categories according to different segmentation rules: threshold-based segmentation algorithms, image boundary-based segmentation algorithms, and region-based image segmentation algorithms.

[0003] In industrial production, considering issues such as real-time performance, algorithm stability, and algorithm computational complexity, threshold-based image segmentation algorithms are usually adopted. Threshold-based segmentation methods emerged earliest, and their implementation principles are simple and the processing speed is fast. Taking image gray-scale threshold segmentation as an example, its basic principle is to select a threshold or multiple thresholds in different regions, and divide the image into different categories according to gray-scale. Therefore, the core of the algorithm lies in the selection of the threshold.

[0004] Among many threshold-based image segmentation algorithms, the maximum inter-class variance method (abbreviated as OTSU method) has been widely applied due to its wide application range, good segmentation effect, stable performance, etc. This algorithm is based on the gray-scale distribution of the image, and takes the maximum inter-class variance between the foreground and background of the image as the selection criterion for the segmentation threshold, and can obtain a good segmentation effect in most cases. However, under different lighting conditions, the gray-scale distribution of the same object image may change greatly. When using the OTSU method for image segmentation of such images, in the case of low brightness, some interference and impurities may be misjudged as the foreground, resulting in segmentation errors. Summary of the Invention

[0005] To solve the above technical problems, the present invention provides a method for calculating an image segmentation threshold based on brightness-weighted maximum inter-class variance, which introduces a threshold weighting coefficient to achieve the purpose of improving the segmentation accuracy and the segmentation effect.

[0006] To achieve the above object, the technical solution of the present invention is as follows:

[0007] A method for calculating an image segmentation threshold based on brightness-weighted maximum inter-class variance includes the following steps:

[0008] Step 1, obtain the functional relationship between the threshold weighting coefficient α and the image brightness b from the image sample;

[0009] Step 2, calculate the brightness b of the image to be segmented d , and calculate the threshold weighting coefficient α according to the functional relationship obtained in Step 1d , and perform amplitude limiting to obtain the amplitude-limited threshold weighting coefficient α′ d ;

[0010] Step 3: Count the number of pixels corresponding to each gray level of the image to be segmented, obtain the gray-level distribution of the image, and find the gray-level value T corresponding to the foreground peak of the gray-level distribution of the image to be segmented through a loop comparison method left_d ;

[0011] Step 4: Use the Otsu method to segment the image to be segmented, and find the Otsu threshold T of the image to be segmented otsu_d ;

[0012] Step 5: Use the amplitude-limited threshold weighting coefficient α′ d , the gray-level value T left_d and the Otsu threshold T otsu_d to calculate the final image segmentation threshold T f_d .

[0013] In the above solution, the specific method of Step 1 is as follows:

[0014] (1) Obtain a series of object image samples with different brightnesses, and calculate their brightnesses b (b1, b2, …, b i , …, b n ), where n is the number of image samples, and b i represents the brightness of the i-th image;

[0015] (2) Manually determine the ideal segmentation threshold T f (T f_1 , T f_2 , …, T f_i , …, T f_n ), where T f_i represents the ideal segmentation threshold of the i-th image;

[0016] (3) Use the Otsu method to segment this group of image samples, and find the Otsu threshold T otsu (T otsu_1 , T otsu_2 , …, T otsu_i , …, T otsu_n ), where T otsu_i is the Otsu threshold of the i-th image;

[0017] (4) Obtain the gray-level value T corresponding to the foreground peak of the gray-level distribution of each image left (T left_1 , T left_2 , …, T left_i , …, T left_n), where T otsu_i is the gray value corresponding to the foreground peak of the gray level distribution of the i-th image; and calculate its threshold weighting coefficient α(α1, α2, …, α i , …, α n ), where α i represents the threshold weighting coefficient of the i-th image;

[0018] (5) Fit the functional relationship between the threshold weighting coefficient α and the image brightness b.

[0019] In a further technical solution, in step (1), the brightness b of the i-th image i is calculated as follows:

[0020]

[0021] where M×N is the number of pixel points of the i-th image, and h(x, y) is the gray value at the position (x, y).

[0022] In a further technical solution, in step (2), first manually determine the foreground and background of the image, and then use a drawing tool to mark the segmentation line between the foreground and background as the segmentation standard for this group of images; secondly, manually set an initial value of its segmentation threshold according to the brightness of each image, and the higher the brightness, the higher the initial value of the threshold; then continuously adjust the segmentation threshold according to the segmentation effect so that the segmentation line between the foreground and background segmented from the image at this threshold coincides with the segmentation line in the manually marked segmentation standard as much as possible; finally, record the ideal segmentation thresholds T f (T f_1 , T f_2 , …, T f_i , …, T f_n ) of n images.

[0023] In a further technical solution, the specific process of step (3) is as follows:

[0024] ① Assume that the gray level of the i-th image is L = 256, select a segmentation threshold t ∈ [0, 255], and divide the pixels of the image into two parts: foreground A and background B;

[0025] ② If the number of pixels with gray value k in the image is q, then the probability of the pixel with gray value k appearing is:

[0026]

[0027] and there is M×N is the number of pixel points of the i-th image;

[0028] ③ When the segmentation threshold is t, the probability that a pixel is assigned to the foreground A is P A(t), the average gray value of foreground A is m A (t); Similarly, the probability that a pixel is assigned to background B is P B (t), and the average gray value of background B is m B (t);

[0029] ④ Let the gray value of the entire image be m G , then there is:

[0030] m G = P A (t)·m A (t) + P B (t)·m B (t) (3)

[0031] P A (t) + P B (t) = 1 (4)

[0032] ⑤ The between-class variance of foreground A and background G is:

[0033] σ 2 (t) = P A (t)·(m A (t) - m G ) 2 + P B (t)·(m B (t) - m G ) 2 (5) Substitute formulas (3) and (4) into formula (5) to get:

[0034] σ 2 (t) = P A (t)·P B (t)·(m A (t) - m B (t)) 2 (6) Then the maximum between-class variance threshold of the i-th image is:

[0035] T otsu_i = argmaxσ 2 (t) (7).

[0036] In a further technical solution, the specific method of step (4) is as follows: First, obtain the gray distribution of the i-th image. The gray map of the object image shows a bimodal distribution on the left and right sides. If the left side is the foreground and the right side is the background, then the gray value corresponding to the left peak is the required value. Assume that the gray value corresponding to the foreground peak of the gray distribution of the i-th image is T left_i , then the corresponding threshold weighting coefficient α i is:

[0037]

[0038] In a further technical solution, the specific method of step (5) is as follows:

[0039] Taking the brightness b of the image as the independent variable and the threshold weighting coefficient α as the dependent variable, and using the least squares method to fit the curve, a quantitative functional relationship can be obtained:

[0040] α = f(b) (9). In the above solution, in step two, the brightness b of the image to be segmented is calculated using formula (1) d ; The clipping formula is as follows:

[0041] if α d > 1, then α' d = 1; if α d < 0, then α' d = 0 (10).

[0042] In the above solution, in step four, the maximum between-class variance threshold T of the image to be segmented is obtained using formulas (2) to (7) otsu_d .

[0043] In the above solution, in step five, the calculation formula of the final image segmentation threshold T f_d is as follows:

[0044] T f_d = α' d · T otsu_d + (1 - α' d ) · T left_d (11).

[0045] Through the above technical solution, a method for calculating an image segmentation threshold based on brightness-weighted maximum between-class variance provided by the present invention has the following beneficial effects:

[0046] By introducing a threshold weighting coefficient, the present invention solves the problem that it is difficult to distinguish impurities, interference from the foreground of the image in the OTSU algorithm in the case of low brightness, and can obtain the functional relationship between the threshold weighting coefficient and the image brightness through statistical calculation of the gray distribution of the image, thereby improving the segmentation accuracy of the OTSU algorithm and the segmentation effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or in the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art.

[0048] Figure 1 It is a schematic flowchart of a method for calculating an image segmentation threshold based on brightness-weighted maximum between-class variance disclosed in an embodiment of the present invention;

[0049] Figure 2 Strain gauge images with different brightnesses;

[0050] Figure 3 Is the grayscale distribution histogram;

[0051] Figure 4 Is the fitting graph of the relationship between the threshold weighting coefficient and brightness;

[0052] Figure 5 Is the comparison between the method of the present invention (TW - OTSU) and the original method (OTSU). Detailed implementation manners

[0053] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention.

[0054] Taking the segmentation of strain gauge images as an example, the present invention will be described in more detail. The present invention provides a method for calculating the image segmentation threshold based on brightness - weighted maximum inter - class variance, as Figure 1 shown, including the following steps:

[0055] Step 1, obtain the functional relationship between the threshold weighting coefficient α and the image brightness b from the strain gauge image samples.

[0056] (1) Obtain a series of strain gauge images with different brightnesses, as Figure 2 shown, and calculate their brightness b through formula (1). Assume there are n (n > 20 to ensure accuracy) images, and their brightnesses are respectively: b1, b2, …, b i , …, b n ;

[0057] The brightness b i of the i - th image is calculated by the following formula:

[0058]

[0059] where M×N is the number of pixel points of the i - th image, and h(x, y) is the grayscale value at the position (x, y).

[0060] (2) Manually determine the ideal segmentation threshold T f . Observe this group of strain gauge images, determine the area of the foreground grid, clarify the edges of the grid and the interference and background polyimide, mark the segmentation line with a drawing tool as the segmentation standard for this group of strain gauge images. Manually set an initial value of its segmentation threshold according to the brightness of each image, and the higher the brightness, the higher the initial value of the threshold; then continuously adjust the segmentation threshold according to the segmentation effect so that the segmentation line between the foreground and background segmented from the strain gauge image under this threshold coincides with the segmentation line in the manually marked segmentation standard as much as possible; finally, record the ideal segmentation thresholds of n images: Tf_1 ,T f_2 ,…,T f_i ,…,t f_n 。

[0061] The splitting principle is to set a grayscale threshold (0 - 255). Pixels in the image with grayscale values higher than this threshold are set as the background (grayscale value set to 0), and pixels lower than this threshold are set as the foreground (grayscale value set to 255). The specific implementation method is to use the cv2.threshold() function in the OpenCV library for splitting. The threshold is adjusted manually. In this step, the foreground and background regions of this group of images are first determined by manual observation. A threshold is manually selected for splitting, and when adjusting, a new threshold is reselected according to the previous result for splitting. In the range of 0 - 255, the result closest to the manually marked standard will be obtained.

[0062] (3) Calculate the maximum between-class variance threshold t otsu 。Using the maximum between-class variance method, perform image segmentation on this group of strain gauge images to find the maximum between-class variance threshold T for each image otsu_1 ,T otsu_2 ,…,T otsu_i ,…,T otsu_n ,The segmentation threshold for the i-th image is T otsu_i ;

[0063] The specific process is as follows:

[0064] ① Assume that the grayscale level of the i-th image is L = 256, select a segmentation threshold t ∈ [0, 255], and divide the pixels of the image into two parts: foreground A and background B;

[0065] ② If the number of pixels with grayscale value k in the image is q, then the probability of pixels with grayscale value k appearing is:

[0066]

[0067] And there is M × N is the number of pixel points of the i-th image;

[0068] ③ When the segmentation threshold is t, the probability of pixels being assigned to the foreground A is P A (t), and the average grayscale value of the foreground A is m A (t); Similarly, the probability of pixels being assigned to the background B is P B (t), and the average grayscale value of the background B is m B (t);

[0069] ④ Assume that the grayscale value of the entire image is m G ,Then there is:

[0070] m G = P A (t)·m A (t)+P B (t)·m B (t) (3)

[0071] P A (t)+P B (t)= 1 (4)

[0072] ⑤ The between-class variance of foreground A and background B is:

[0073] σ 2 (t)= P A (t)·(m A (t)-m G ) 2 +P B (t)·(m B (t)-m G ) 2 (5)

[0074] Substituting formulas (3) and (4) into formula (5) gives:

[0075] σ 2 (t)= P A (t)·P B (t)·(m A (t)-m B (t)) 2 (6)

[0076] Then the maximum between-class variance threshold of the i-th image is:

[0077] T otsu_i = argmax σ 2 (t) (7).

[0078] (4) Obtain the gray value T corresponding to the foreground peak of the image gray distribution, left and calculate the threshold weighting coefficient α.

[0079] First, obtain the gray distribution of the image. The gray scale image of the strain gauge image shows a bimodal distribution. The gray value T corresponding to the left peak left is what we want. Let the gray value corresponding to the foreground peak M_A of the gray distribution of the i-th image be T left_i , as Figure 3 shown. In the figure, M_B is the right peak, that is, the background peak; then the corresponding threshold weighting coefficient is:

[0080]

[0081] (5) Fit the relationship between the threshold weighting coefficient α and the image brightness b.

[0082] Taking the luminance b calculated in step (1) as the independent variable and the threshold weighting coefficient α calculated in step (4) as the dependent variable, the least squares method is used to fit the curve to obtain a quantitative functional relationship α = f(b). For this example, as Figure 4 shown, a cubic function fitting is selected:

[0083] α = C·b 3 + D·b 2 + E·b + F (12)

[0084] After calculation, it can be obtained that:

[0085] C = 3.3290×10 -7 , D = -0.0001, E = 0.0100, F = 0.3969 (13)

[0086] Substituting formula (13) into formula (12), the fitted curve is as shown in formula (14):

[0087] α = 3.329×10 -7 ·b 3 -0.0001·b 2 + 0.01·b + 0.3969 (14).

[0088] Step 2: Calculate the luminance b of the image to be segmented d , assuming the size of the image to be segmented is M d ×N d , the gray value at position (x d , y d ) is h d (x d , y d ). According to formula (1), the luminance of the image to be segmented can be calculated as:

[0089]

[0090] Then, according to the functional relationship formula (14) obtained in step 1, calculate the threshold weighting coefficient α d , and perform clipping according to formula (10) to obtain the clipped threshold weighting coefficient α′ d :

[0091] if α d > 1, then α′ d = 1; if α d < 0, then α′ d = 0 (10).

[0092] Step 3: Count the number of pixels corresponding to each gray level of the image to be segmented to obtain the gray distribution of the image, and obtain the gray value T corresponding to the foreground peak of the gray distribution of the image to be segmented through a loop comparison method left_d 。

[0093] Step 4: Segment the image to be segmented using the maximum inter-class variance method, that is, use formulas (2) to (7) to find the maximum inter-class variance threshold T of the image to be segmented otsu 。

[0094] Step 5: Use the limited threshold weighting coefficient α′ d 、gray value T left_d and the maximum inter-class variance threshold T otsu_d to calculate the final image segmentation threshold T f_d :

[0095] T f_d =α′ d ·T otsu_d +(1 - α′ d )·T left_d (11)

[0096] To verify the effectiveness of the calculation method of the present invention, another strain gauge image was selected to calculate the image segmentation threshold according to the above method and perform segmentation. To clearly show the effectiveness of the present invention, only the local part containing interference is shown. A total of four groups of segmentation experiments were carried out, and each group of experiments had three pictures. The original picture (O) was on the left, the segmentation effect picture of the original OTSU algorithm was in the middle, and the segmentation effect picture of the algorithm of the present invention (TW-OTSU) was on the right. The results are as Figure 5 shown. By comparing with the original picture, it can be seen that the irregular silk-like objects in the middle of the image are impurity interferences. The method of the present invention can solve the problem that it is difficult to distinguish the foreground from impurity interferences under low brightness, and the segmentation effect using the obtained segmentation threshold is significantly better than the original OTSU algorithm

[0097] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but will be accorded the widest scope consistent with the principles and novel features disclosed herein

Claims

1. An image segmentation threshold calculation method based on brightness weighted between-class variance, characterized in that It includes the following steps: Step 1: Obtain the threshold weighting coefficient from the image sample and the function relationship with the image brightness ; Step 2: Calculate the brightness of the image to be segmented , and calculate the threshold weighting coefficient according to the function relationship obtained in Step 1 , and perform amplitude limiting to obtain the amplitude-limited threshold weighting coefficient ; Step 3: Count the number of pixels corresponding to each gray level of the image to be segmented, obtain the gray level distribution of the image, and obtain the gray level value corresponding to the foreground peak of the gray level distribution of the image to be segmented by means of loop comparison ; Step 4: Use the Otsu method to perform image segmentation on the image to be segmented, and find the Otsu threshold of the image to be segmented ; Step 5: Use the threshold weighting coefficient after amplitude limiting , grayscale value and the maximum inter-class variance threshold to calculate the final image segmentation threshold ; In step (1), the brightness of the first image is calculated as follows: (1) Among them, is the number of pixel points of the th image, and is the gray value at the position The specific method of step (4) is as follows: First, obtain the gray-scale distribution of the th image. The gray-scale image of the object image shows a bimodal distribution on the left and right sides. If the left side is the foreground and the right side is the background, then the gray-scale value corresponding to the left peak is the one we want. Assume that the gray-scale value corresponding to the foreground peak of the th image is , then the corresponding threshold weighting coefficient is: (8) Among them, represents the ideal segmentation threshold of the th image; is the maximum between-class variance threshold of the th image; In step 2, the brightness of the image to be segmented is calculated using formula (1). ; The formula for clipping is as follows: (10) In step five, the calculation formula for the final image segmentation threshold is as follows: (11)。 2. The image segmentation threshold calculation method based on brightness weighted maximum inter-class variance according to claim 1, characterized in that The specific method of Step 1 is as follows: (1) Obtain a series of object image samples with different brightness levels, and calculate their brightness respectively , where is the number of image samples, represents the th brightness of the image; (2) Manually determine the ideal segmentation threshold for each image , where represents the ideal segmentation threshold of the th image; (3) Use the Otsu method to perform image segmentation on this group of image samples, and find the Otsu threshold of each image. , where is the Otsu threshold of the (4) Obtain the gray value corresponding to the foreground peak of the gray distribution of each image , where is the gray value corresponding to the foreground peak of the gray distribution of the -th image; and calculate its threshold weighting coefficient according to the ideal segmentation threshold and the maximum between-class variance threshold , where represents the threshold weighting coefficient of the -th image; (5) Fitting threshold weighting coefficient Function relationship with image brightness of 3. The method for calculating the image segmentation threshold based on brightness weighted maximum between-class variance according to claim 2, wherein In step (2), first, manually determine the foreground and background of the image, and then use a drawing tool to mark the dividing line between the foreground and the background as the segmentation standard for this group of images; secondly, manually set an initial value of its segmentation threshold according to the brightness of each image, and the higher the brightness, the higher the initial value of the threshold; then continuously adjust the segmentation threshold according to the segmentation effect so that the dividing line between the foreground and the background segmented from the image at this threshold coincides with the dividing line in the manually marked segmentation standard as much as possible; finally, record the ideal segmentation thresholds of images 4. A method for calculating an image segmentation threshold based on luminance weighted maximum between-class variance according to claim 2, characterized in that, The specific process of Step (3) is as follows: ① Let the gray level of the th image be , select a segmentation threshold , and divide the pixels of the image into foreground and background in two parts; ② If the number of pixels with a gray value of in the image is , then the probability of the pixel with a gray value of appearing is: (2) and there is ; is the number of pixel points of the th image; ③ When the segmentation threshold is the probability that a pixel is assigned to the foreground is , and the average gray value of the foreground is ; Similarly, the probability that a pixel is assigned to the background is , and the average gray value of the background is ; ④Let the grayscale value of the entire image be , then we have: (3) (4) ⑤Foreground and background The between-class variance is as follows: (5) Substituting Formulas (3) and (4) into Formula (5), we get: (6) Then the between-class variance threshold of the th image is: (7)。 5. A method for calculating an image segmentation threshold based on luminance weighted maximum between-class variance according to claim 2, characterized in that, The specific method of Step (5) is as follows: With the brightness of the image as the independent variable and the threshold weighting coefficient as the dependent variable, the least squares method is used to fit the curve, and a quantitative functional relationship can be obtained: (9)。 6. A method for calculating an image segmentation threshold based on brightness weighted maximum between-class variance according to claim 4, characterized in that, In Step 4, the maximum inter-class variance threshold of the image to be segmented is obtained using Formulas (2) to (7). .

Citation Information

Patent Citations

  • Image threshold segmentation method and device based on fuzzy set and Otsu

    CN108510499A

  • Method, apparatus, and program for applying binarizing or multi-value processing to image

    JP2005354287A