Image segmentation threshold determination method, device, and electronic device
By combining FCM clustering with the dynamic threshold method, the image segmentation threshold is dynamically determined, which solves the problem of inaccurate image segmentation in the existing technology and achieves clearer image boundaries and higher segmentation accuracy.
Patent Information
- Application Number
- CN202211510981.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-29
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-11-29
AI Technical Summary
Existing threshold-based image segmentation methods produce inaccurate segmentation results when the grayscale difference is small and the object has many texture features. They are prone to over-segmentation and it is difficult to achieve optimal threshold segmentation in different application scenarios to improve image segmentation accuracy.
The FCM clustering segmentation algorithm is used to judge the segmentation results of small-sized image blocks. The naive Bayesian classification method is combined to adjust the initial threshold. The dynamic threshold method is used to judge the segmentation results of large-sized image blocks, and the final image segmentation threshold is dynamically determined.
The accuracy of image segmentation is improved, image boundaries are clearer, the segmentation requirements of image blocks of different sizes are adapted, and the overall effect of image segmentation is improved.
Smart Images

Figure CN115810024B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method and device for determining an image segmentation threshold, an electronic device, and a computer-readable storage medium. Background Art
[0002] Image segmentation is the process of subdividing an image into multiple image sub-regions (a collection of pixels, also called superpixels). The purpose of image segmentation is to simplify or change the representation of an image so that the image is easier to understand and analyze. Image segmentation is usually used to locate objects and boundaries (lines, curves, etc.) in an image. More precisely, image segmentation is the process of labeling each pixel in an image, which makes pixels with the same label have certain common visual characteristics. In the prior art, the commonly used threshold-based image segmentation method will not produce accurate segmentation results when the grayscale difference of the image is not large and there are too many texture features of the object, resulting in over-segmentation. Due to the complexity of natural images and application scenarios, how to use the optimal threshold to segment images of different types and different application scenarios to improve the accuracy of image segmentation is a topic that technicians in this field are constantly studying. Summary of the Invention
[0003] The embodiments of the present application provide a method, device, and electronic device for determining an image segmentation threshold, which can improve the accuracy of threshold-based image segmentation.
[0004] In a first aspect, an embodiment of the present application discloses a method for determining an image segmentation threshold, comprising:
[0005] Obtaining an initial segmentation result obtained by performing initial segmentation on the image to be segmented;
[0006] Segment and sample the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks, wherein the image blocks include: a first image block with an image size smaller than a preset size threshold and a second image block with an image size greater than or equal to the preset size threshold;
[0007] Using the FCM clustering segmentation algorithm to determine the segmentation result of the first image block, and obtaining a first image segmentation threshold;
[0008] Using a dynamic threshold method to determine the segmentation result of the second image block, and obtaining a second image segmentation threshold;
[0009] A final image segmentation threshold of the image to be segmented is determined according to the first image segmentation threshold and the second image segmentation threshold.
[0010] Optionally, the using an FCM clustering segmentation algorithm to determine a segmentation result of the first image block to obtain a first image segmentation threshold includes:
[0011] Clustering the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category that matches each of the first image blocks;
[0012] Using a naive Bayesian classification method to predict the probability that the first image block matches the corresponding image block category, to obtain a predicted probability that the first image block matches the corresponding image block category;
[0013] According to the predicted probability, the initial image segmentation threshold is selectively adjusted to obtain a first image segmentation threshold.
[0014] Optionally, selectively adjusting the initial image segmentation threshold according to the predicted probability to obtain a first image segmentation threshold includes:
[0015] In response to the predicted probability being greater than or equal to a preset probability threshold, using the initial image segmentation threshold as a first image segmentation threshold corresponding to the first image block;
[0016] In response to the predicted probability being less than the preset probability threshold, the initial image segmentation threshold is adjusted, and the process jumps to the step of segmenting and sampling the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, and re-segmentation sampling is performed.
[0017] Optionally, the using a dynamic threshold method to determine the segmentation result of the second image block to obtain the second image segmentation threshold includes:
[0018] Determining an image segmentation threshold interval according to the initial image segmentation threshold;
[0019] Acquire multiple candidate image segmentation thresholds within the image segmentation threshold interval;
[0020] performing simulated segmentation on the second image block according to the initial segmentation result and each candidate image segmentation threshold, and obtaining the clarity of each third image block obtained by the simulated segmentation using each candidate image segmentation threshold;
[0021] A second image segmentation threshold is obtained according to the clarity of each third image block.
[0022] Optionally, obtaining a second image segmentation threshold according to the clarity of each third image block includes:
[0023] Obtaining a ratio of clear image blocks in each third image block obtained by simulated segmentation using each candidate image segmentation threshold, wherein the clear image block is: the third image block whose image clarity meets a preset clarity condition;
[0024] The candidate image segmentation threshold corresponding to the maximum value of the proportion is determined as the second image segmentation threshold.
[0025] In a second aspect, an embodiment of the present application discloses a device for determining an image segmentation threshold, comprising:
[0026] An initial segmentation result acquisition module is used to obtain an initial segmentation result obtained by performing initial segmentation on the image to be segmented;
[0027] a segmentation sampling module, configured to segment and sample the image to be segmented according to the initial segmentation result and the initial image segmentation threshold, to obtain a plurality of image blocks, wherein the image blocks include: a first image block having an image size smaller than a preset size threshold and a second image block having an image size greater than or equal to the preset size threshold;
[0028] A first image segmentation threshold acquisition module is used to use the FCM clustering segmentation algorithm to determine the segmentation result of the first image block and obtain a first image segmentation threshold;
[0029] A second image segmentation threshold acquisition module, configured to use a dynamic threshold method to determine the segmentation result of the second image block and acquire a second image segmentation threshold;
[0030] The image segmentation threshold determination module is used to determine a final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold.
[0031] Optionally, the first image segmentation threshold acquisition module is further used to:
[0032] Clustering the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category that matches each of the first image blocks;
[0033] Using a naive Bayesian classification method to predict the probability that the first image block matches the corresponding image block category, to obtain a predicted probability that the first image block matches the corresponding image block category;
[0034] According to the predicted probability, the initial image segmentation threshold is selectively adjusted to obtain a first image segmentation threshold.
[0035] Optionally, selectively adjusting the initial image segmentation threshold according to the predicted probability to obtain a first image segmentation threshold includes:
[0036] In response to the predicted probability being greater than or equal to a preset probability threshold, using the initial image segmentation threshold as a first image segmentation threshold corresponding to the first image block;
[0037] In response to the predicted probability being less than the preset probability threshold, the initial image segmentation threshold is adjusted, and the process jumps to the step of segmenting and sampling the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, and re-segmentation sampling is performed.
[0038] Optionally, the second image segmentation threshold acquisition module is further used to:
[0039] Determining an image segmentation threshold interval according to the initial image segmentation threshold;
[0040] Acquire multiple candidate image segmentation thresholds within the image segmentation threshold interval;
[0041] performing simulated segmentation on the second image block according to the initial segmentation result and each candidate image segmentation threshold, and obtaining the clarity of each third image block obtained by the simulated segmentation using each candidate image segmentation threshold;
[0042] A second image segmentation threshold is obtained according to the clarity of each third image block.
[0043] Optionally, obtaining a second image segmentation threshold according to the clarity of each third image block includes:
[0044] Obtaining a ratio of clear image blocks in each third image block obtained by simulated segmentation using each candidate image segmentation threshold, wherein the clear image block is: the third image block whose image clarity meets a preset clarity condition;
[0045] The candidate image segmentation threshold corresponding to the maximum value of the proportion is determined as the second image segmentation threshold.
[0046] In a third aspect, an embodiment of the present application further discloses an electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the image segmentation threshold determination method described in the embodiment of the present application is implemented.
[0047] In a fourth aspect, an embodiment of the present application discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps of the image segmentation threshold determination method disclosed in an embodiment of the present application.
[0048] The image segmentation threshold determination method disclosed in the embodiment of the present application obtains an initial segmentation result obtained by performing initial segmentation on the image to be segmented; segments and samples the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, wherein the image blocks include: a first image block with an image size less than a preset size threshold and a second image block with an image size greater than or equal to the preset size threshold; uses the FCM clustering segmentation algorithm to judge the segmentation result of the first image block to obtain a first image segmentation threshold; uses the dynamic threshold method to judge the segmentation result of the second image block to obtain a second image segmentation threshold; determines the final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold, thereby realizing dynamic determination of the boundary area segmentation threshold for image blocks of different sizes, improving the accuracy of the determined image segmentation threshold, thereby improving the accuracy of image segmentation, and making the image boundary obtained by cutting clearer.
[0049] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0051] Figure 1 is a flowchart of the method for determining an image segmentation threshold value disclosed in an embodiment of the present application;
[0052] Figure 2 This is a schematic diagram of an application scenario of the image segmentation threshold determination method disclosed in an embodiment of the present application;
[0053] Figure 3 This is a schematic diagram of the optimization process of the first image block segmentation threshold in the image segmentation threshold determination method disclosed in an embodiment of the present application;
[0054] Figure 4 This is a schematic diagram of the second image block segmentation threshold optimization process in the image segmentation threshold determination method disclosed in an embodiment of the present application;
[0055] Figure 5 Schematic diagram of the structure of the image segmentation threshold determination device disclosed in an embodiment of the present application;
[0056] Figure 6 A block diagram schematically shows an electronic device for executing the method according to the present application; and
[0057] Figure 7 The figure schematically shows a storage unit for storing or carrying a program code for implementing the method according to the present application. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0059] The following is an example of the specific implementation of the method for determining the image segmentation threshold value disclosed in the embodiment of the present application.
[0060] like Figure 1 As shown, an image segmentation threshold determination method disclosed in an embodiment of the present application includes: steps 110 to 150.
[0061] Step 110: Obtain an initial segmentation result obtained by performing initial segmentation on the image to be segmented.
[0062] In some embodiments of the present application, the image to be segmented may be an image of a product packaging, a poster, a photograph, or the like.
[0063] The segmentation method used when performing the initial segmentation of the image to be segmented is determined according to specific business requirements. For example, a threshold segmentation method can be used to perform the initial segmentation of the image to be segmented to obtain the initial segmentation result.
[0064] Threshold segmentation is the most widely used segmentation method. The basic idea is to first find the optimal threshold value based on the grayscale features of the image according to a certain criterion, and then compare the grayscale value of each pixel in the image with the value, and finally classify each pixel into the appropriate category based on the comparison result.
[0065] Threshold segmentation can use one or more segmentation thresholds to divide an image into several target and background regions. If there is only a single threshold, it is single-threshold image segmentation, also known as image binarization. The method of image segmentation based on multiple thresholds is called multi-value image segmentation. The purpose of the threshold segmentation method is to divide the pixel set according to image information (such as the grayscale value of each pixel in the image, the grayscale value distribution characteristics of neighboring pixels, etc.) so that each subset forms a region corresponding to the real scene, or each region exhibits homogeneous characteristics.
[0066] Let I(i, j) represent the pixel value in the i-th row and j-th column of image I. If I is a grayscale image, then I(i, j) is a covariate; if I is a color image, then I(i, j) is a vector. Taking I as an example, assuming the image grayscale level is L, image single threshold segmentation is to classify pixels in image I with values less than a threshold t into one class C2, and pixels in image I with values greater than a threshold t into another class C1, where t can be less than the image grayscale level L. The segmentation result can be expressed as follows:
[0067] C1={I(i,j)∈I|0≤I(i,j)≤t-1};
[0068] C2={I(i,j)∈I|t≤I(i,j)≤L-1};
[0069] In image multi-threshold segmentation, multiple thresholds need to be set.
[0070] The specific implementation of the threshold segmentation method can be found in the prior art and will not be described in detail in the embodiments of this application.
[0071] In the embodiment of the present application, there is no limitation on the specific implementation method for obtaining the initial segmentation result.
[0072] Step 120 : Segment and sample the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks.
[0073] The image blocks include: a first image block whose image size is smaller than a preset size threshold and a second image block whose image size is greater than or equal to the preset size threshold.
[0074] In the field of image segmentation, in order to improve segmentation accuracy, it is usually necessary to further segment the boundary area of two segmented image blocks to improve the problem of over-segmentation of the image or blurred segmentation edges.
[0075] In the embodiment of the present application, the initial image segmentation threshold is the ratio of further dividing the boundary area of two image areas into the two image areas. Figure 2For example, in the two image regions 210 and 220 shown in FIG, a portion of pixels in the dotted-line framed region 230 at the intersection of image regions 210 and 220 can be assigned to image region 210, while another portion can be assigned to image region 220. The result of assigning region 230 to image regions 210 and 220 will affect the visual effects of image regions 210 and 220. For example, if image regions 210 and 220 are the background and foreground regions, respectively, the result of assigning region 230 to image regions 210 and 220 will affect the clarity of foreground objects relative to the background.
[0076] To accurately segment region 230, in the embodiment of the present application, region 230 is first segmented using an initial image segmentation threshold. For example, the initial image segmentation threshold can be set to 80%, which means that 80% of the left side of region 230 is divided into image region 210, and 20% of the right side of region 230 is divided into image region 220. According to this method, the image to be segmented is segmented into multiple image blocks.
[0077] In some embodiments of the present application, due to differences in the image to be segmented, the sizes of the multiple image blocks obtained when the image to be segmented is segmented and sampled according to the initial segmentation result and the initial image segmentation threshold may also vary. For example, when the image to be segmented includes multiple smaller foreground objects, the segmented image blocks will include image blocks corresponding to multiple smaller foreground objects. Similarly, when the image to be segmented includes a larger foreground object, the segmented image blocks will include image blocks corresponding to the larger foreground object.
[0078] In some embodiments of the present application, a size threshold of an image block can be pre-set. When the size of the segmented image block is smaller than the preset size threshold, the image block is recorded as a "first image block"; and when the size of the segmented image block is greater than or equal to the preset size threshold, the image block is recorded as a "second image block."
[0079] Through this step, only a plurality of first image blocks may be obtained, only a plurality of second image blocks may be obtained, or both the first image blocks and the second image blocks may be obtained.
[0080] Step 130: Use the FCM clustering segmentation algorithm to determine the segmentation result of the first image block and obtain a first image segmentation threshold.
[0081] The image segmentation algorithm based on FCM clustering has better segmentation effect for classifying small-sized images. In the embodiment of the present application, the FCM clustering segmentation algorithm is used to judge the segmentation result of the first image block to determine whether the image block segmentation is accurate. If it is inaccurate, the initial image segmentation threshold is adjusted and the segmentation sampling is re-performed; if it is accurate, the segmentation result is retained.
[0082] like Figure 3 As shown, in some embodiments of the present application, the FCM clustering segmentation algorithm is used to determine the segmentation result of the first image block to obtain the first image segmentation threshold, including: sub-step 1301, sub-step 1302 and sub-step 1303.
[0083] Sub-step 1301: clustering the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category that matches each of the first image blocks.
[0084] The FCM clustering method uses clustering to segment images, maximizing the similarity between samples assigned to the same class and minimizing the similarity between samples assigned to different classes. The FCM clustering algorithm optimizes the objective function to determine the degree of membership of each sample relative to all class centers, thereby determining the class of the sample points and automatically classifying the sample data.
[0085] In the embodiment of the present application, the FCM-based image segmentation algorithm divides the image blocks into several classes by minimizing the objective function, where each class of image blocks belongs to a specific image region. The objective function is a function of the membership matrix U and the cluster center set V, and its expression is as follows:
[0086]
[0087] In the above formula, V = {V1, V2...Vc} cluster set; c is the number of cluster centers; membership matrix U = {u ij}(u ij ∈[0,1]), where is used to represent the probability that the jth sample belongs to the ith class, d ij is the distance between the i-th cluster center and the j-th sample, and m is a weighted exponent. When m = 1, FCM degenerates into the classic Hard C-Means (HCM). FCM iteratively updates the membership matrix U and the set of cluster centers V until a certain termination condition is met, at which point the algorithm terminates and obtains the final membership matrix and set of cluster centers.
[0088] The specific implementation of the FCM clustering algorithm can be found in the prior art and will not be described in detail in the embodiments of this application.
[0089] After performing FCM clustering segmentation on the first image block, the matching category of each image block is obtained.
[0090] Sub-step 1302 : using a naive Bayes classification method to predict the probability that the first image block matches the corresponding image block category, to obtain a predicted probability that the first image block matches the corresponding image block category.
[0091] In order to make the image segmentation results obtained by FCM clustering more accurate (for example, to make the boundaries of the segmented image blocks clearer), in an embodiment of the present application, a naive Bayesian classification prediction model is used to predict the image segmentation results obtained by FCM clustering, and the probability that each image block in the current image classification result belongs to the current classification is obtained. If the probability is lower than 50%, the image block is re-segmented and sampled.
[0092] Bayes' theorem is the basis of the Naive Bayesian Classifier. If there are m classification categories in a given data set, the Naive Bayesian Classifier can predict whether a given observation belongs to the specific category with the highest posterior probability. In other words, when the Naive Bayesian Classifier predicts that X belongs to category C, it means that:
[0093] P(C i |X)>P(C j |X)1≤j≤m,j≠i;
[0094] At this time, if we maximize P(C i |X), its P(C i |X) The largest class C i It is called the maximum a posteriori hypothesis, and according to Bayes' theorem: It can be seen that since P(X) is equal for all categories, only P(X|C i )P(C i ) can be maximized.
[0095] Specifically in the embodiment of the present application, in order to predict the category of a second image block, the probability P(C i ) and the probability P(X|C) of the second image block X in this category i ), thereby obtaining the predicted probability that the second image block belongs to each category.
[0096] Sub-step 1303: selectively adjust the initial image segmentation threshold according to the predicted probability to obtain a first image segmentation threshold.
[0097] Next, the accuracy of the FCM clustering image segmentation result is determined based on the prediction results of the Bayesian classification model. If the FCM clustering image segmentation result is accurate, then the initial image segmentation threshold is accurate. If the FCM clustering image segmentation result is inaccurate, then the initial image segmentation threshold is inaccurate and needs to be adjusted.
[0098] In some embodiments of the present application, the selective adjustment of the initial image segmentation threshold based on the predicted probability to obtain the first image segmentation threshold includes: in response to the predicted probability being greater than or equal to the preset probability threshold, using the initial image segmentation threshold as the first image segmentation threshold corresponding to the first image block; in response to the predicted probability being less than the preset probability threshold, adjusting the initial image segmentation threshold, and jumping to the step of segmenting and sampling the image to be segmented based on the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, and re-segmenting and sampling.
[0099] In some embodiments of the present application, a probability threshold can be set in advance. When the predicted probability is greater than or equal to the preset probability threshold, the initial image segmentation threshold is considered to be accurate; when the predicted probability is less than the preset probability threshold, the initial image segmentation threshold is considered to be inaccurate.
[0100] If it is determined that the initial image segmentation threshold is accurate, the initial image segmentation threshold is used as the first image segmentation threshold corresponding to the first image block; if it is determined that the initial image segmentation threshold is inaccurate, the initial image segmentation threshold is adjusted to obtain an adjusted image segmentation threshold; and based on the adjusted image segmentation threshold and the initial segmentation result, the image to be segmented is re-segmented and sampled to obtain multiple image blocks, and step 130 is executed again.
[0101] After resegmenting and sampling the image to be segmented, the first image block and the second image block obtained may change. If the cluster segmentation results of the first image block obtained after resegmentation and sampling are accurate, the adjusted initial image segmentation threshold can be used as the first image segmentation threshold.
[0102] Step 140: Use a dynamic threshold method to determine the segmentation result of the second image block to obtain a second image segmentation threshold.
[0103] For larger image blocks, i.e., the second image blocks, there is usually a problem of blurred cutting edges, which is not suitable for FCM cluster segmentation. In the embodiment of the present application, a dynamic threshold method is used to determine the segmentation result of the second image block to determine whether the initial image segmentation threshold is accurate. If it is inaccurate, a more accurate image segmentation threshold is selected.
[0104] In some embodiments of the present application, Figure 4 As shown, the step of using the dynamic threshold method to determine the segmentation result of the second image block and obtaining the second image segmentation threshold includes: sub-step 1401, sub-step 1402, sub-step 1403 and sub-step 1404.
[0105] Sub-step 1401: determining an image segmentation threshold interval according to the initial image segmentation threshold.
[0106] In an embodiment of the present application, the image segmentation threshold interval is obtained by floating the initial image segmentation threshold used to cut the second image block up and down by a preset amplitude value (e.g., 10%). Taking the initial image segmentation threshold of 80% as an example, floating the image segmentation threshold by 10% can obtain an image segmentation threshold interval of 70% to 90%.
[0107] Sub-step 1402: Acquire multiple candidate image segmentation thresholds within the image segmentation threshold interval.
[0108] Then, the image segmentation threshold interval is divided into candidate image segmentation thresholds of equal step size. Still taking the image segmentation threshold interval of 70% to 90% as an example, the floating 20% interval range is divided into 10 parts with a step size of 2%, resulting in 10 candidate image segmentation thresholds: 72%, 74%, ..., 90%.
[0109] Sub-step 1403 : performing simulated segmentation on the second image block according to the initial segmentation result and each candidate image segmentation threshold, and obtaining the clarity of each third image block obtained by the simulated segmentation using each candidate image segmentation threshold.
[0110] Afterwards, for each candidate image segmentation threshold, a simulated segmentation and clarity calculation operation is performed.
[0111] For example, for a candidate image segmentation threshold of 72%, the method of simulating step 120 in which the image to be segmented is segmented and sampled based on the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks is simulated. Based on the initial segmentation result and each candidate image segmentation threshold, the second image block is simulated for segmentation to obtain multiple image blocks, denoted as "third image blocks." For each third image block, the clarity of the third image block is calculated using conventional methods to obtain the clarity of the segmentation result when the image is segmented based on the candidate image segmentation threshold of 72%.
[0112] In the same way, the clarity of the segmentation results when image segmentation is performed according to each candidate image segmentation threshold is obtained.
[0113] Sub-step 1404: obtaining a second image segmentation threshold according to the clarity of each third image block.
[0114] After executing the aforementioned steps, the clarity of the segmentation result when image segmentation is performed according to each candidate image segmentation threshold can be obtained. Next, based on the clarity of the third image block corresponding to each candidate image segmentation threshold, a candidate image segmentation threshold is selected that makes the third image block clearer.
[0115] In some embodiments of the present application, obtaining the second image segmentation threshold based on the clarity of each third image block includes: obtaining the proportion of clear image blocks in each third image block obtained by simulated segmentation based on each candidate image segmentation threshold, wherein the clear image block is: the third image block whose image clarity meets a preset clarity condition; and determining the candidate image segmentation threshold corresponding to the maximum value of the proportion as the second image segmentation threshold.
[0116] For example, the number of clear image blocks can be determined based on a comparison of the clarity of the third image block obtained by segmentation at each candidate image segmentation threshold with a preset clarity condition. Furthermore, the proportion of clear image blocks can be determined as the proportion corresponding to each candidate image segmentation threshold. The candidate image segmentation threshold with the largest proportion can then be selected as the second image segmentation threshold.
[0117] In some embodiments of the present application, any candidate image segmentation threshold whose corresponding proportion is greater than or equal to a preset ratio threshold (such as 70%) may be selected as the second image segmentation threshold.
[0118] Step 150: Determine a final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold.
[0119] After obtaining a first image segmentation threshold applicable to a first image block of smaller size and a second image segmentation threshold applicable to a second image block of larger size, for a smaller image area obtained by segmenting the image to be segmented based on grayscale values, the first image segmentation threshold can be used to perform segmentation adjustment on the boundary area of the first image block; for a larger image area obtained by segmenting the image to be segmented based on grayscale values, the second image segmentation threshold can be used to perform segmentation adjustment on the boundary area of the second image block, thereby obtaining clearer image blocks.
[0120] The image segmentation threshold determination method disclosed in the embodiment of the present application obtains an initial segmentation result obtained by performing initial segmentation on the image to be segmented; segments and samples the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, wherein the image blocks include: a first image block with an image size less than a preset size threshold and a second image block with an image size greater than or equal to the preset size threshold; uses the FCM clustering segmentation algorithm to judge the segmentation result of the first image block to obtain a first image segmentation threshold; uses the dynamic threshold method to judge the segmentation result of the second image block to obtain a second image segmentation threshold; determines the final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold, thereby realizing dynamic determination of the boundary area segmentation threshold for image blocks of different sizes, improving the accuracy of the determined image segmentation threshold, thereby improving the accuracy of image segmentation, and making the image boundary obtained by cutting clearer.
[0121] The image segmentation threshold determination method disclosed in the embodiment of the present application first cuts and samples the image using a traditional threshold-based segmentation method, and then uses the FCM clustering image segmentation method to perform image segmentation classification on the sampled data to optimize the cutting threshold of the cutting boundary of the small-sized image block. Then, for the large-sized image block obtained based on the threshold cutting, a grayscale value-based comparison algorithm is introduced to judge the clarity of the cut image under different thresholds, thereby optimizing the cutting threshold of the cutting boundary of the large-sized image block. This can effectively solve the problem of blurred cutting edges when using the cutting threshold to segment the boundary area of the image block.
[0122] Correspondingly, the embodiment of the present application also discloses a device for determining an image segmentation threshold value, such as Figure 5 As shown, the device includes:
[0123] The initial segmentation result acquisition module 510 is used to obtain the initial segmentation result obtained by performing initial segmentation on the image to be segmented;
[0124] a segmentation sampling module 520 configured to segment and sample the image to be segmented based on the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks, wherein the image blocks include: a first image block having an image size smaller than a preset size threshold and a second image block having an image size greater than or equal to the preset size threshold;
[0125] A first image segmentation threshold acquisition module 530 is configured to determine a segmentation result of the first image block using an FCM clustering segmentation algorithm to acquire a first image segmentation threshold;
[0126] A second image segmentation threshold acquisition module 540 is configured to determine the segmentation result of the second image block using a dynamic threshold method to acquire a second image segmentation threshold;
[0127] The image segmentation threshold determination module 550 is configured to determine a final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold.
[0128] In some embodiments of the present application, the first image segmentation threshold acquisition module 530 is further configured to:
[0129] Clustering the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category that matches each of the first image blocks;
[0130] Using a naive Bayesian classification method to predict the probability that the first image block matches the corresponding image block category, to obtain a predicted probability that the first image block matches the corresponding image block category;
[0131] According to the predicted probability, the initial image segmentation threshold is selectively adjusted to obtain a first image segmentation threshold.
[0132] In some embodiments of the present application, selectively adjusting the initial image segmentation threshold according to the predicted probability to obtain a first image segmentation threshold includes:
[0133] In response to the predicted probability being greater than or equal to a preset probability threshold, using the initial image segmentation threshold as a first image segmentation threshold corresponding to the first image block;
[0134] In response to the predicted probability being less than the preset probability threshold, the initial image segmentation threshold is adjusted, and the process jumps to the step of segmenting and sampling the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, and re-segmentation sampling is performed.
[0135] In some embodiments of the present application, the second image segmentation threshold acquisition module 540 is further configured to:
[0136] Determining an image segmentation threshold interval according to the initial image segmentation threshold;
[0137] Acquire multiple candidate image segmentation thresholds within the image segmentation threshold interval;
[0138] performing simulated segmentation on the second image block according to the initial segmentation result and each candidate image segmentation threshold, and obtaining the clarity of each third image block obtained by the simulated segmentation using each candidate image segmentation threshold;
[0139] A second image segmentation threshold is obtained according to the clarity of each third image block.
[0140] In some embodiments of the present application, obtaining the second image segmentation threshold according to the clarity of each third image block includes:
[0141] Obtaining a ratio of clear image blocks in each third image block obtained by simulated segmentation using each candidate image segmentation threshold, wherein the clear image block is: the third image block whose image clarity meets a preset clarity condition;
[0142] The candidate image segmentation threshold corresponding to the maximum value of the proportion is determined as the second image segmentation threshold.
[0143] The image segmentation threshold determination device disclosed in the embodiment of the present application is used to implement the image segmentation threshold determination method described in the embodiment of the present application. The specific implementation methods of each module of the device will not be repeated here. Please refer to the specific implementation methods of the corresponding steps in the method embodiment.
[0144] The image segmentation threshold determination device disclosed in the embodiment of the present application obtains an initial segmentation result obtained by performing initial segmentation on the image to be segmented; segments and samples the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain multiple image blocks, wherein the image blocks include: a first image block with an image size less than a preset size threshold and a second image block with an image size greater than or equal to the preset size threshold; uses the FCM clustering segmentation algorithm to judge the segmentation result of the first image block to obtain a first image segmentation threshold; uses the dynamic threshold method to judge the segmentation result of the second image block to obtain a second image segmentation threshold; determines the final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold, thereby realizing dynamic determination of the boundary area segmentation threshold for image blocks of different sizes, improving the accuracy of the determined image segmentation threshold, thereby improving the accuracy of image segmentation, and making the image boundary obtained by cutting clearer.
[0145] The image segmentation threshold determination device disclosed in the embodiment of the present application first cuts and samples the image using a traditional threshold-based segmentation method, and then uses the FCM clustering image segmentation method to perform image segmentation classification on the sampled data to optimize the cutting threshold of the cutting boundary of the small-sized image block. Then, for the large-sized image block obtained based on the threshold cutting, a grayscale value-based comparison algorithm is introduced to judge the clarity of the cut image under different thresholds, thereby optimizing the cutting threshold of the cutting boundary of the large-sized image block. This can effectively solve the problem of blurred cutting edges when using the cutting threshold to segment the boundary area of the image block.
[0146] Each embodiment in this specification is described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between the various embodiments can be referred to in conjunction with each other. For the device embodiments, since they are generally similar to the method embodiments, their description is relatively simple, and for relevant parts, reference can be made to the description of the method embodiments.
[0147] The above is a detailed introduction to a method and device for determining an image segmentation threshold provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
[0148] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0149] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all of the functions of some or all of the components in the electronic device according to the embodiment of the present application. The application can also be implemented as a device or apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0150] For example, Figure 6An electronic device that can implement the method according to the present application is shown. The electronic device can be a PC, a mobile terminal, a personal digital assistant, a tablet computer, etc. The electronic device conventionally includes a processor 610 and a memory 620, and program code 630 stored on the memory 620 and executable on the processor 610. When the processor 610 executes the program code 630, the method described in the above embodiments is implemented. The memory 620 can be a computer program product or a computer-readable medium. The memory 620 can be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Memory), an EPROM, a hard disk, or a ROM. The memory 620 has a storage space 6201 for program code 630 of a computer program for executing any of the method steps described above. For example, the storage space 6201 for program code 630 can include individual computer programs for implementing various steps in the above method. The program code 630 is computer-readable code. These computer programs can be read from or written to one or more computer program products. These computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards, or floppy disks. The computer program includes a computer-readable code, and when the computer-readable code is run on an electronic device, the electronic device is caused to execute the method according to the above embodiment.
[0151] The embodiment of the present application further discloses a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the steps of the image segmentation threshold determination method as described in the embodiment of the present application are implemented.
[0152] Such a computer program product may be a computer-readable storage medium having a computer program product. Figure 6 The memory 620 in the electronic device shown is similarly arranged as a storage segment, storage space, etc. The program code can be compressed and stored in the computer readable storage medium in an appropriate form. The computer readable storage medium is generally as shown in FIG. Figure 7 The portable or fixed storage unit generally includes computer-readable code 630', which is a code read by a processor and implements the steps of the above-described method when executed by the processor.
[0153] References herein to "one embodiment," "an embodiment," or "one or more embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Furthermore, please note that instances of the phrase "in one embodiment" do not necessarily all refer to the same embodiment.
[0154] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of this description.
[0155] In the claims, any reference signs placed between brackets shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in the claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present application may be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by one and the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for determining an image segmentation threshold, characterized in that: include: Obtaining an initial segmentation result obtained by performing initial segmentation on the image to be segmented; Segment and sample the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks, wherein the image blocks include: a first image block with an image size smaller than a preset size threshold and a second image block with an image size greater than or equal to the preset size threshold; Clustering the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category that matches each of the first image blocks; Using a naive Bayesian classification method to predict the probability that the first image block matches the corresponding image block category, to obtain a predicted probability that the first image block matches the corresponding image block category; In response to the predicted probability being greater than or equal to a preset probability threshold, using the initial image segmentation threshold as a first image segmentation threshold corresponding to the first image block; In response to the predicted probability being less than the preset probability threshold, adjusting the initial image segmentation threshold, and jumping to the step of segmenting and sampling the image to be segmented according to the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks, and re-segmenting and sampling; Determining an image segmentation threshold interval according to the initial image segmentation threshold; Acquire multiple candidate image segmentation thresholds within the image segmentation threshold interval; performing simulated segmentation on the second image block according to the initial segmentation result and each candidate image segmentation threshold, and obtaining the clarity of each third image block obtained by the simulated segmentation using each candidate image segmentation threshold; obtaining a second image segmentation threshold according to the clarity of each third image block; A final image segmentation threshold of the image to be segmented is determined according to the first image segmentation threshold and the second image segmentation threshold.
2. The method according to claim 1, characterized in that The obtaining of a second image segmentation threshold according to the clarity of each third image block includes: Obtaining a ratio of clear image blocks in each third image block obtained by simulated segmentation using each candidate image segmentation threshold, wherein the clear image block is: the third image block whose image clarity meets a preset clarity condition; The candidate image segmentation threshold corresponding to the maximum value of the proportion is determined as the second image segmentation threshold.
3. A device for determining an image segmentation threshold, characterized in that: The device comprises: An initial segmentation result acquisition module is used to obtain an initial segmentation result obtained by performing initial segmentation on the image to be segmented; a segmentation sampling module, configured to segment and sample the image to be segmented according to the initial segmentation result and the initial image segmentation threshold, to obtain a plurality of image blocks, wherein the image blocks include: a first image block having an image size smaller than a preset size threshold and a second image block having an image size greater than or equal to the preset size threshold; a first image segmentation threshold acquisition module, configured to cluster the first image blocks using an FCM clustering segmentation algorithm to obtain an image block category matching each of the first image blocks; predict the probability of the first image blocks matching the corresponding image block category using a naive Bayesian classification method to obtain a predicted probability of the first image blocks matching the corresponding image block category; in response to the predicted probability being greater than or equal to a preset probability threshold, use the initial image segmentation threshold as the first image segmentation threshold corresponding to the first image block; in response to the predicted probability being less than the preset probability threshold, adjust the initial image segmentation threshold, and jump to the step of segmenting and sampling the image to be segmented based on the initial segmentation result and the initial image segmentation threshold to obtain a plurality of image blocks, and re-segment and sample; a second image segmentation threshold acquisition module, configured to determine an image segmentation threshold interval based on the initial image segmentation threshold; obtain a plurality of candidate image segmentation thresholds within the image segmentation threshold interval; perform simulated segmentation on the second image block based on the initial segmentation result and each of the candidate image segmentation thresholds, obtain the clarity of each third image block obtained by the simulated segmentation using each of the candidate image segmentation thresholds; and obtain a second image segmentation threshold based on the clarity of each third image block; The image segmentation threshold determination module is used to determine a final image segmentation threshold of the image to be segmented according to the first image segmentation threshold and the second image segmentation threshold.
4. An electronic device comprising a memory, a processor, and a program code stored in the memory and executable on the processor, wherein: When the processor executes the program code, the image segmentation threshold determination method according to any one of claims 1 to 2 is implemented.
5. A computer-readable storage medium having program code stored thereon, characterized in that: When the program code is executed by a processor, the steps of the image segmentation threshold determination method according to any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
Purple soil image self-adaptive segmentation extraction method based on improved FCM algorithm
CN110084820A
Autonomous extraction method for welding seam position based on naive Bayes classifier
CN113762400A