An image adaptive segmentation algorithm based on improved edge detection

By improving the image adaptive segmentation algorithm based on edge detection, and utilizing the OTSU algorithm, an improved image center selection method, and a shadow detection mechanism, the problems of long processing time and low efficiency in existing image segmentation technologies are solved, achieving more efficient and accurate image segmentation results.

CN119941771BActive Publication Date: 2025-10-17HUBEI UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510087530.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-20
Publication Date
2025-10-17
Estimated Expiration
2045-01-20

AI Technical Summary

Technical Problem

Metaheuristic algorithms and deep learning techniques, along with threshold segmentation algorithms, suffer from long processing times and low efficiency when processing images, making them particularly unsuitable for large-scale or real-time image processing scenarios.

Method used

An image adaptive segmentation algorithm based on improved edge detection is adopted. The optimal threshold is found by using the OTSU algorithm. Combined with the improved image center selection method and shadow detection mechanism, the optimal image center point of the foreground region is determined. The start and end points of the target region to be segmented are selected. When shadows are present, the segmentation start and end points are reset to eliminate interference from impurities.

Benefits of technology

It improves the accuracy and efficiency of image segmentation, effectively eliminates shadow and noise interference, improves recall, and is suitable for segmentation processing of complex images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119941771B_ABST
    Figure CN119941771B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image segmentation technology, and discloses an image adaptive segmentation algorithm based on improved edge detection, comprising the following steps: inputting an image to be segmented P, performing grayscale conversion and binarization segmentation to obtain a grayscale image P , ; Use OTSU algorithm to find the grayscale image P , The optimal threshold in the grayscale image P is converted according to the optimal threshold , The method is divided into a foreground area and a background area; the optimal image center point of the foreground area is confirmed and the target area to be segmented is selected, and the starting point and the end point of the target area to be segmented are determined; it is judged whether there is a shadow in the foreground area. If so, a shadow detection mechanism is introduced to reset the segmentation starting point and end point of the foreground area before segmentation; otherwise, the image is directly segmented; the image is saved and output. The present invention achieves better segmentation by using a dynamic threshold based on the improved OTSU algorithm, and determines the starting / end point of the cutting area through continuity detection, effectively eliminating magazines and other interference factors, and the algorithm can identify the target more accurately.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image segmentation, in particular to an image adaptive segmentation algorithm based on improved edge detection. BACKGROUND

[0002] According to the different processing methods, the image segmentation algorithm can be divided into four main technologies: threshold-based segmentation, edge-based segmentation, region-based segmentation and theory-based segmentation, among which the threshold-based image segmentation method uses gray information and threshold extraction, and by setting one or more thresholds, the pixels are divided into different categories, so as to segment the image and effectively separate the background from the foreground. Threshold-based segmentation has been widely used in image processing, and has the advantages of stable performance, simple model and easy implementation, and is widely used in various fields of image segmentation processing.

[0003] In complex images, according to the difference between the target region and the background region, the optimal threshold value needs to be selected for image segmentation, and the image is divided into target region and background region, and the selection of the optimal threshold value directly affects the segmentation effect. Scholars have introduced meta-heuristic algorithms to optimize the process and improve the segmentation accuracy. In addition, the deep learning technology is combined with the threshold segmentation algorithm to improve the training efficiency of the deep learning model and improve the segmentation accuracy.

[0004] The random search capability of meta-heuristic algorithms (MAs) enables the segmentation algorithm to identify the optimal solution in a wide solution space, even with uncertainty, without the need to traverse the entire space. This capability greatly reduces search time and computational cost. The integration of deep learning technology and threshold segmentation algorithm usually involves applying threshold algorithms before or after the deep learning model to improve training efficiency or improve segmentation accuracy. However, both algorithms process all pixels in the image. As the number of pixels increases, the classification accuracy and segmentation accuracy also increase. However, this also leads to longer processing time and lower efficiency, making these methods less suitable for large-scale or real-time image processing scenarios. SUMMARY

[0005] The purpose of the present application is to solve the problem of long processing time and low efficiency of meta-heuristic algorithms and deep learning technology and threshold segmentation algorithm, and to propose an image adaptive segmentation algorithm based on improved edge detection.

[0006] The technical solution of the present application to solve the above technical problems is as follows:

[0007] An image adaptive segmentation algorithm based on improved edge detection, comprising the following steps:

[0008] S1, input the image to be segmented P and perform gray scale and binary segmentation to obtain a gray scale image P ,;

[0009] S2. Use OTSU algorithm to find the grayscale image P , The optimal threshold in the grayscale image P is converted according to the optimal threshold. , Divided into foreground area and background area;

[0010] S3, using an improved image center selection method to determine the optimal image center point of the foreground area;

[0011] S4, using the optimal image center point to select the target area to be segmented, and determining the two endpoints of the target area to be segmented as the starting point and end point of the segmentation;

[0012] S5. Determine whether there is a shadow in the foreground area. If yes, introduce a shadow detection mechanism and reset the segmentation start and end points of the foreground area before segmentation. Otherwise, segment directly.

[0013] S6. Save the image and output it.

[0014] On the basis of the above technical solution, the present invention can also be improved as follows.

[0015] Preferably, the specific steps of S3 are as follows:

[0016] First, in the grayscale image P , Take one point at 1 / 3 and 2 / 3 of the rows and columns in the foreground area, and a total of four intersection points as the central reference points. Then perform sparse processing on the points on the vertical or horizontal coordinate axis where these four central reference points are located. Then calculate the grayscale values ​​of the row or column coordinate points of these four points, and set the part greater than the optimal threshold to 255, and the part lower than the optimal threshold to 0. Finally, count the number of coordinate points with a grayscale value of 255, select the row or column with the largest number as the reference line, and use the intersection of the row or column as the optimal image center point.

[0017] Preferably, the specific steps of S4 are as follows:

[0018] The optimal center point is used as the origin to establish a plane rectangular coordinate system. First, the grayscale values ​​at different horizontal coordinates in the x-axis direction of the foreground area are analyzed. The horizontal axis corresponding to the horizontal coordinate of the optimal center point and the grayscale value are used to establish the first coordinate system. The minimum horizontal coordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the dividing line. , The foreground area is divided into several areas, and the area with the largest number of points with a grayscale value of 255 is selected as the target area to be segmented, and the left and right endpoints of the area are determined as the starting and end points of the segmentation; secondly, the grayscale values ​​at different vertical coordinates in the y-axis direction of the foreground area are analyzed, and the vertical axis corresponding to the vertical coordinate of the optimal center point and the grayscale value are used to establish a second coordinate system. The minimum vertical coordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the dividing line, and the grayscale image P is divided into, The foreground region is divided into several regions, one of the regions with the most number of points with a gray value of 255 is selected as a target region to be divided, and the upper and lower endpoints of the region are determined as the starting point and the ending point of the division.

[0019] Preferably, the specific steps of S5 are as follows:

[0020] When the distance between the starting point or the ending point of the division and the edge of the image to be divided is greater than 5 coordinate points, the difference between the average values of the gray values of the 5 adjacent points before and after the starting point or the ending point of the division is calculated, if the difference is less than 10, it is determined that there is a shadow, then the starting point or the ending point of the region with the shadow is reset to the edge of the image, and the division is performed again, if the difference is greater than 10, it is determined that there is no shadow, and the division can be directly performed, when the distance between the starting point or the ending point of the division and the edge of the image to be divided is less than 5 coordinate points, it is determined that there is no shadow, and the division can be directly performed.

[0021] Compared with the prior art, the technical scheme of the present application has the following beneficial technical effects:

[0022] 1. The improved OTSU algorithm-based dynamic threshold is used for better division, the starting / ending point of the cutting region is determined through continuity detection, the interference of impurities and other factors is effectively excluded, the algorithm can more accurately identify the target, and the improved image center point selection method adopts a multi-center point strategy, so that the algorithm is not easily affected by local changes in the image when processing complex images.

[0023] 2. The starting / ending point determination method of the cutting region based on continuity detection effectively excludes the interference of impurities and improves the recall rate. BRIEF DESCRIPTION OF DRAWINGS

[0024] Figure 1 Pre-segmentation diagram for the row or column where the optimal image center point of the present application falls in the deep shadow region;

[0025] Figure 2 Pre-segmentation diagram for the row or column where the optimal image center point of the present application falls in the deep shadow region; Figure 1 Post-segmentation diagram;

[0026] Figure 3 Post-segmentation diagram; Figure 1 Diagram showing the change in the gray value of the horizontal axis point in the present application;

[0027] Figure 4 Diagram showing the change in the gray value of the horizontal axis point in the present application; Figure 1 Diagram showing the change in the gray value of the horizontal axis point in the present application;

[0028] Figure 5 Pre-segmentation diagram for the row or column where the optimal image center point of the present application falls in the deep shadow region;

[0029] Figure 6 Post-segmentation diagram; Figure 5The middle horizontal axis point gray value change condition schematic diagram;

[0030] Figure 7 For the present application Figure 5 The middle horizontal axis point gray value change condition schematic diagram;

[0031] Figure 8 For the present application the optimal image center point falls outside the segmentation target area before segmentation schematic diagram;

[0032] Figure 9 For the present application Figure 8 After segmentation schematic diagram;

[0033] Figure 10 For the present application the segmentation starting point falls in the noise area before segmentation schematic diagram;

[0034] Figure 11 For the present application Figure 10 After segmentation schematic diagram;

[0035] Figure 12 For the present application Figure 10 The middle horizontal axis point gray value change condition schematic diagram;

[0036] Figure 13 For the present application Figure 10 The middle horizontal axis point gray value change condition schematic diagram. DETAILED DESCRIPTION

[0037] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0038] An image adaptive segmentation algorithm based on improved edge detection includes the following steps:

[0039] S1, input the image to be segmented P and perform gray scale and binary segmentation to obtain a gray scale image P , ;

[0040] S2, find the optimal threshold value in the gray scale image P , using the OTSU algorithm, and divide the gray scale image P , into a foreground region and a background region according to the optimal threshold value;

[0041] S3, use an improved image center selection method to confirm the optimal image center point of the foreground region;

[0042] S4, selecting the target region to be segmented by using the optimal image center point, and determining the two end points of the target region to be segmented as the starting point and the ending point of segmentation;

[0043] S5, judging whether the shadow exists in the foreground region, if yes, introducing the shadow detection mechanism, resetting the starting point and the ending point of segmentation of the foreground region, and then segmenting; otherwise, directly segmenting;

[0044] S6, saving the image and outputting.

[0045] The specific steps of S3 are as follows:

[0046] Firstly, in the gray image P , The 1 / 3 and 2 / 3 of the row and column of the foreground region are taken as 1 point, and a total of 4 intersection points are taken as center reference points, and then the points on the vertical or horizontal coordinate axis of the 4 center reference points are sparsely processed, and then the gray values of the row or column coordinate points are calculated, and the part greater than the optimal threshold value is set to 255, and the part lower than the optimal threshold value is set to 0, and finally the number of coordinate points with a gray value of 255 is counted, and the row or column with the largest number is selected as the reference line, and the intersection point of the row or column is taken as the optimal image center point.

[0047] The specific steps of S4 are as follows:

[0048] A plane rectangular coordinate system is established with the optimal center point as the origin, firstly, the gray values at different horizontal coordinates in the x-axis direction of the foreground region are analyzed, a first coordinate system is established with the horizontal axis line corresponding to the horizontal coordinate of the optimal center point and the gray value, the smallest horizontal coordinate corresponding to the point with a gray value of 255 in the foreground region is taken as the segmentation line, and the gray image P , The foreground region is segmented into a plurality of regions, one region with the largest number of points with a gray value of 255 in the plurality of regions is selected as the target region to be segmented, and the left and right two end points of the region are determined as the starting point and the ending point of segmentation; secondly, the gray values at different vertical coordinates in the y-axis direction of the foreground region are analyzed, a second coordinate system is established with the vertical axis line corresponding to the vertical coordinate of the optimal center point and the gray value, and the smallest vertical coordinate corresponding to the point with a gray value of 255 in the foreground region is taken as the segmentation line, and the gray image P , The foreground region is segmented into a plurality of regions, one region with the largest number of points with a gray value of 255 in the plurality of regions is selected as the target region to be segmented, and the upper and lower two end points of the region are determined as the starting point and the ending point of segmentation.

[0049] The specific steps of S5 are as follows:

[0050] When the distance between the segmentation starting point or the segmentation ending point and the edge of the image to be segmented is greater than 5 coordinate points, the difference between the average values of the gray values of the 5 points adjacent to the segmentation starting point or the segmentation ending point is calculated, if the difference is less than 10, it is determined that there is a shadow, and then the segmentation starting point or the ending point of the area with the shadow is reset to the edge of the image, and the segmentation is performed again; if the difference is greater than 10, it is determined that there is no shadow, and the segmentation can be directly performed; when the distance between the segmentation starting point or the segmentation ending point and the edge of the image to be segmented is less than 5 coordinate points, it is determined that there is no shadow, and the segmentation can be directly performed.

[0051] When the OTSU algorithm is used for image segmentation, it is often disturbed by shadows. In particular, when the row or column where the center point of the image falls in a deep shadow area (the center point of the image is the point with the highest gray value in the image) Figure 1 , the gray value of these areas may become 0 in the binarization process, causing these points to be ignored in the detection process, and thus the shadow area may be incorrectly removed in the segmentation, causing the transition segmentation phenomenon Figure 2 . In order to solve this problem, a shadow detection mechanism is introduced. Before segmentation, the algorithm first detects whether there is a shadow in the image. If there is a shadow (the center point of the image is the point with the highest gray value in the image) Figure 1 , the row where the center point falls will pass through the shadow area, and the gray value of these points will change relatively smoothly, i.e. the gray value will change slowly with a certain slope Figure 3 . On the contrary, if the column does not pass through the shadow area, the gray value of the points will change more obviously. If there is no shadow (the center point of the image is the point with the highest gray value in the image) Figure 5 , the gray value on the row or column where the center point falls will change obviously Figure 6 and Figure 7 , so that the background area and the target area can be easily distinguished. Therefore, the shadow detection mechanism is: when the distance between the segmentation point (starting point or ending point) and the edge of the image to be segmented is less than 5 coordinate points, it is determined that there is no shadow area. If the distance is greater than 5 coordinate points, the algorithm calculates the difference between the average values of the gray values of the 5 points adjacent to the segmentation point. If the difference is greater than 10, it indicates that there is no shadow in the area, and the segmentation can be directly performed. If the difference is less than 10, it indicates that there is a shadow, and then the algorithm resets the segmentation starting point or the ending point of the area with the shadow to the edge of the image, and then performs the segmentation again.

[0052] The Magefreehome algorithm is used to calculate the size of the image and determine the position of the center point of the image. If the center point falls outside the target segmentation area (the center point of the image is the point with the highest gray value in the image) Figure 8 , the gray value of the coordinate point in the row / column where the center point falls will be lower than the set threshold, which will cause the image to be excessively cropped (the center point of the image is the point with the highest gray value in the image) Figure 9 .

[0053] The target area for segmentation is usually no smaller than 1 / 9 of the image. Based on this, an improved method for selecting image center points is proposed: first, a point is selected at 1 / 3 and 2 / 3 of the image row and column, a total of four intersection points as the center reference points. To reduce the amount of calculation, the points on the vertical / horizontal coordinate axis where these four reference points are located are thinned out to reduce the number of coordinate points (for example, by a factor of 4, that is, retaining one point for every three points). Then, the grayscale values ​​of these four row / column coordinate points are calculated, and the dynamic threshold is calculated using the OTSU algorithm, and the image is binarized. Finally, the number of coordinate points with a grayscale value of 255 is counted, and the row / column with the largest number is selected as the reference line, with the intersection of these rows / columns as the target center point.

[0054] The Magefreehome algorithm is susceptible to noise when determining the segmentation start and end points. That is, when the start / end point falls in a noisy area with high grayscale values ​​outside the target area (when there are debris such as data cables, fingers, and bottle caps), the noisy area will be mistakenly considered as part of the target area, resulting in incomplete segmentation. Figure 10 The middle starting point falls in the noise area, Figure 11 The segmented image still contains noise areas.

[0055] Therefore, a method for determining the segmentation start / end point based on continuity detection is designed. The principle is to determine whether there is noise by detecting the continuity of the coordinates of the points with a grayscale value of 255 in the row / column where the center point is located. This is because the coordinates of the points with a grayscale value of 255 in the target area to be segmented are generally distributed continuously, and the coordinates will not jump ( Figure 12 ), while noise will cause the coordinate values ​​to mutate and no longer be continuous ( Figure 13 Therefore, this paper stipulates that when determining the start / end point of the image: if the coordinate spacing of the point with a grayscale value of 255 does not exceed 1 / 10 of the total length of the row (column), it is considered as a continuous coordinate, indicating that there is no noise interference. In this case, the segment with the largest number of coordinate points is selected as the target area to be segmented, and the two endpoints of this segment are determined as the start and end points of the segmentation.

[0056] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0057] While embodiments of the present application have been shown and described, it is to be understood that various modifications, substitutions, replacements and variations can be made to these embodiments without departing from the principles and spirit of the present application, the scope of which is defined by the appended claims and their equivalents.

Claims

1. An image adaptive segmentation algorithm based on improved edge detection, characterized in that: The following steps are involved: S1. Input the image to be segmented P and perform grayscale conversion and binarization segmentation to obtain the grayscale image P. , ; S2. Use OTSU algorithm to find the grayscale image P , The optimal threshold in the grayscale image P is converted according to the optimal threshold , Divided into foreground area and background area; S3, using an improved image center selection method to determine the optimal image center point of the foreground area; S4, using the optimal image center point to select the target area to be segmented, and determining the two endpoints of the target area to be segmented as the starting point and end point of the segmentation; S5. Determine whether there is a shadow in the foreground area. If yes, introduce a shadow detection mechanism and reset the segmentation start and end points of the foreground area before segmentation. Otherwise, segment directly. S6. Save the image and output it; The specific steps of S5 are as follows: When the distance between the segmentation starting point or the segmentation end point and the edge of the image to be segmented is greater than 5 coordinate points, the difference between the average grayscale values ​​of the 5 adjacent points before and after the segmentation starting point or the segmentation end point is calculated. If the difference is less than 10, it is determined that there is a shadow, and the segmentation starting point or the end point of the shadow area is reset to the image edge and then segmented; if the difference is greater than 10, it is determined that there is no shadow and it can be segmented directly; when the distance between the segmentation starting point or the segmentation end point and the edge of the image to be segmented is less than 5 coordinate points, it is determined that there is no shadow and it can be segmented directly.

2. The image adaptive segmentation algorithm based on improved edge detection according to claim 1, characterized in that: The specific steps of S3 are as follows: First, in the grayscale image P , Take one point at 1 / 3 and 2 / 3 of the rows and columns in the foreground area, and a total of four intersection points as the central reference points. Then perform sparse processing on the points on the vertical or horizontal coordinate axis where these four central reference points are located. Then calculate the grayscale values ​​of the row or column coordinate points of these four points, and set the part greater than the optimal threshold to 255, and the part lower than the optimal threshold to 0. Finally, count the number of coordinate points with a grayscale value of 255, select the row or column with the largest number as the reference line, and use the intersection of the row or column as the optimal image center point.

3. The image adaptive segmentation algorithm based on improved edge detection according to claim 1, characterized in that: The specific steps of S4 are as follows: The optimal center point is used as the origin to establish a plane rectangular coordinate system. First, the grayscale values ​​at different horizontal coordinates in the x-axis direction of the foreground area are analyzed. The horizontal axis corresponding to the horizontal coordinate of the optimal center point and the grayscale value are used to establish the first coordinate system. The minimum horizontal coordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the dividing line. , The foreground area is divided into several areas, and the area with the largest number of points with a grayscale value of 255 is selected as the target area to be segmented, and the left and right endpoints of the area are determined as the starting and ending points of the segmentation; Secondly, the grayscale values ​​at different ordinates in the y-axis direction of the foreground area are analyzed, and the vertical axis corresponding to the ordinate of the optimal center point and the grayscale value are used to establish a second coordinate system. The minimum vertical coordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the dividing line. , The foreground area is divided into several areas, and the area with the largest number of points with a grayscale value of 255 is selected as the target area to be segmented, and the upper and lower endpoints of the area are determined as the starting and end points of the segmentation.

Citation Information

Patent Citations

  • Threshold segmentation method for USB surface defect detection

    CN111754538A

  • Character segmentation method and apparatus, and computer-readable storage medium

    EP4071665A1