Image adaptive segmentation algorithm based on improved edge detection

By improving the OTSU algorithm and image center point selection method, combined with the shadow detection mechanism, an improved image adaptive segmentation algorithm is proposed, which solves the problems of long processing time and low efficiency in the existing technology, and achieves more efficient image segmentation.

CN119941771AActive Publication Date: 2025-05-06HUBEI UNIV OF TECH
View PDF 3 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Metaheuristic algorithms, deep learning technologies and threshold segmentation algorithms have problems of long processing time and low efficiency when processing images, and are especially not suitable for large-scale or real-time image processing scenarios.

Method used

An image adaptive segmentation algorithm based on improved edge detection is proposed. By improving OTSU algorithm, the starting point and end point of the segmented area are dynamically adjusted by combining the improved image center point selection method and shadow detection mechanism.

Benefits of technology

This algorithm can more accurately identify targets, improve recall, reduce impurity interference, and improve segmentation efficiency. It is suitable for large-scale or real-time image processing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119941771A_ABST
    Figure CN119941771A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image segmentation, and discloses an image adaptive segmentation algorithm based on improved edge detection, which comprises the following steps: inputting an image P to be segmented, and carrying out graying and binarization segmentation to obtain a grayscale image P; searching an optimal threshold value in the grayscale image P by using an OTSU algorithm, and dividing the grayscale image P into a foreground region and a background region according to the optimal threshold value; determining an optimal image center point of the foreground region, selecting a to-be-segmented target region, and determining a starting point and an ending point of the to-be-segmented target region; judging whether a shadow exists in the foreground region or not, if so, introducing a shadow detection mechanism, resetting a segmentation starting point and an end point of the foreground region, and then performing segmentation; otherwise, directly segmenting; according to the method, through the dynamic threshold value based on the improved OTSU algorithm, better segmentation is achieved, the starting point / ending point of the segmentation area is determined through continuous detection, magazines and other interference factors are effectively eliminated, and the algorithm can recognize a target more accurately.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of image segmentation, and in particular to an image adaptive segmentation algorithm based on improved edge detection. Background Art

[0002] According to different processing methods, image segmentation algorithms can be divided into four main technologies: threshold-based segmentation, edge-based segmentation, region-based segmentation and theory-based segmentation. Among them, the threshold-based image segmentation method uses grayscale information and threshold extraction to divide pixels into different categories by setting one or more thresholds, thereby segmenting the image and effectively separating the background from the foreground. Threshold-based segmentation has been widely used in image processing. It has the advantages of stable performance, simple model, and easy implementation. It is widely used in various fields of image segmentation processing.

[0003] In complex images, according to the differences between the target area and the background area, it is necessary to select the optimal threshold for image segmentation to divide the image into the target area and the background area. The selection of the optimal threshold directly affects the segmentation effect. Scholars have introduced meta-heuristic algorithms to optimize the processing and improve the segmentation accuracy. In addition, 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 metaheuristic algorithms (MAs) enables segmentation algorithms to identify optimal solutions in a wide range of solution spaces, even in the presence of uncertainty, without traversing the entire space. This capability significantly reduces search time and computational cost. The integration of deep learning techniques with threshold segmentation algorithms usually involves applying a threshold algorithm 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, classification accuracy and segmentation accuracy also increase. However, this also results in longer processing time and lower efficiency, making these methods less suitable for large-scale or real-time image processing scenarios. Summary of the invention

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

[0006] The technical solution of the present invention to solve the above technical problems is as follows: An image adaptive segmentation algorithm based on improved edge detection comprises the following steps: S1. Input the image to be segmented P and perform grayscale conversion and binarization segmentation to obtain a grayscale image P. , ; S2. Use OTSU algorithm to find grayscale image P , The optimal threshold in the grayscale image P is , Divided into foreground area and background area; S3, confirming the optimal image center point of the foreground area using an improved image center selection method; 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 the end point of the segmentation; S5, judging whether there is a shadow in the foreground area, if yes, introducing a shadow detection mechanism, resetting the segmentation start and end points of the foreground area before segmentation; otherwise, directly segmenting; S6. Save the image and output it.

[0007] Based on the above technical solution, the present invention can also be improved as follows.

[0008] Preferably, 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 are used as central reference points. Then, the points on the vertical or horizontal axis where these four central reference points are located are thinned, and then the grayscale values ​​of the four row or column coordinate points are calculated, and the part greater than the optimal threshold is set to 255, and the part lower than the optimal threshold is set to 0. Finally, the number of coordinate points with a grayscale value of 255 is counted, and the row or column with the largest number is selected as the reference line, and the intersection of the row or column is used as the optimal image center point.

[0009] Preferably, the specific steps of S4 are as follows: The plane rectangular coordinate system is established with the optimal center point as the origin. 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 ordinates in the y-axis direction of the foreground area are analyzed, and the ordinate axis corresponding to the ordinate of the optimal center point is used to establish a second coordinate system with the grayscale value. The minimum ordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the segmentation line, and the grayscale image P is divided into , The foreground area is segmented 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 point and end point of the segmentation.

[0010] Preferably, 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.

[0011] Compared with the prior art, the technical solution of this application has the following beneficial technical effects: 1. The present invention improves the segmentation by using a dynamic threshold based on the improved OTSU algorithm, determines the start / end point of the cutting area by continuity detection, effectively eliminates magazines and other interference factors, and the algorithm can identify the target more accurately. The improved image center point selection method adopts a multi-center point strategy, which makes the algorithm less susceptible to local changes in the image when processing complex images.

[0012] 2. The present invention effectively eliminates the interference of impurities and improves the recall rate through a method for determining the start / end point of a cutting area based on continuity detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 This is a schematic diagram before segmentation when the row or column where the center point of the optimal image of the present invention is located falls within the deep shadow area; Figure 2 For the present invention Figure 1 Schematic diagram after segmentation; Figure 3 For the present invention Figure 1 Schematic diagram of the change of gray value of the middle horizontal axis point; Figure 4 For the present invention Figure 1 Schematic diagram of the change of gray value of the middle vertical axis point; Figure 5 This is a schematic diagram of the present invention before segmentation without the shadow area; Figure 6 For the present invention Figure 5 Schematic diagram of the change of gray value of the middle horizontal axis point; Figure 7 For the present invention Figure 5 Schematic diagram of the change of gray value of the middle vertical axis point; Figure 8 This is a schematic diagram before segmentation in which the center point of the optimal image of the present invention falls outside the segmentation target area; Fig. 9 For the present invention Figure 8 Schematic diagram after segmentation; Fig.10This is a schematic diagram of the present invention before segmentation when the segmentation starting point falls within the noise area; Fig.11 For the present invention Fig.10 Schematic diagram after segmentation; Fig.12 For the present invention Fig.10 Schematic diagram of the change of gray value of the middle horizontal axis point; Fig.13 For the present invention Fig.10 Schematic diagram of the change in grayscale value of the points on the middle vertical axis. DETAILED DESCRIPTION

[0014] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0015] An image adaptive segmentation algorithm based on improved edge detection comprises the following steps: S1. Input the image to be segmented P and perform grayscale conversion and binarization segmentation to obtain a grayscale image P. , ; S2. Use OTSU algorithm to find grayscale image P , The optimal threshold in the grayscale image P is , Divided into foreground area and background area; S3, confirming the optimal image center point of the foreground area using an improved image center selection method; 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 the end point of the segmentation; S5, judging whether there is a shadow in the foreground area, if yes, introducing a shadow detection mechanism, resetting the segmentation start and end points of the foreground area before segmentation; otherwise, directly segmenting; S6. Save the image and output it.

[0016] 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 are used as central reference points. Then, the points on the vertical or horizontal axis where these four central reference points are located are thinned, and then the grayscale values ​​of the four row or column coordinate points are calculated, and the part greater than the optimal threshold is set to 255, and the part lower than the optimal threshold is set to 0. Finally, the number of coordinate points with a grayscale value of 255 is counted, and the row or column with the largest number is selected as the reference line, and the intersection of the row or column is used as the optimal image center point.

[0017] The specific steps of S4 are as follows: The plane rectangular coordinate system is established with the optimal center point as the origin. 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 ordinates in the y-axis direction of the foreground area are analyzed, and the ordinate axis corresponding to the ordinate of the optimal center point is used to establish a second coordinate system with the grayscale value. The minimum ordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the segmentation line, and the grayscale image P is divided into , The foreground area is segmented 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 point and end point of the segmentation.

[0018] 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.

[0019] When using the OTSU algorithm for image segmentation, it is often disturbed by shadows. Especially when the row or column where the center point of the image is located falls in a deep shadow area ( Figure 1 ), the grayscale values ​​of these areas may become 0 during the binarization process, causing these points to be ignored during the detection process, and the shadow area may be mistakenly removed during segmentation, resulting in transitional segmentation ( Figure 2 ). 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 ( Figure 1 ), the row where the center point is located will pass through the shadow area, and the grayscale value of these points will change relatively smoothly, that is, the grayscale value changes slowly with a certain slope ( Figure 3 ). On the contrary, if the column does not pass through the shaded area, the gray value change of the point will be more obvious. If there is no shadow ( Figure 5 ), the gray value on the row or column where the center point is located will have an obvious mutation ( 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 end point) and the edge of the image to be segmented is less than 5 coordinate points, it is judged as a shadow-free area. If the distance is greater than 5 coordinate points, the algorithm will calculate the difference between the average grayscale values ​​of the 5 adjacent points before and after the segmentation point. If the difference is greater than 10, it means that there is no shadow in the area and it can be segmented directly. If the difference is less than 10, it means that there is a shadow. At this time, the algorithm will reset the segmentation start or end point of the shadow area to the edge of the image, and then segment it.

[0020] The Magefreehome algorithm calculates the image size to determine the center point of the image. If the center point falls outside the segmentation target area ( Figure 8 ), when the gray value of the row / column coordinate point where the center point is located is lower than the set threshold, it will cause the image to be over-cropped ( Fig. 9 ).

[0021] The target area of ​​segmentation is usually not less than 1 / 9 of the image. Based on this, an improved method for selecting the center point of the image is proposed: first, a point is selected at 1 / 3 and 2 / 3 of the image row and column, and a total of 4 intersection points are used as the center reference point. In order to reduce the amount of calculation, the points on the vertical / horizontal coordinate axis where these 4 reference points are located are sparsely processed to reduce the number of coordinate points (for example, 4 times, that is, 1 point is retained every 3 points); then the grayscale values ​​of the row / column coordinate points of these 4 points are calculated, and the dynamic threshold is calculated using the OTSU algorithm, and then 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, and the intersection of the row / column is used as the target center point.

[0022] The Magefreehome algorithm is easily affected by noise when determining the segmentation start and end points. That is, when the start / end point falls in a noise area with a high grayscale value outside the segmentation target area (when there are debris such as data cables, fingers, bottle caps, etc.), the noise area will be mistaken for part of the segmentation target area, and the segmentation will be incomplete. Fig.10 The middle starting point falls in the noise area. Fig.11 The segmented image still contains noise areas.

[0023] 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 coordinate continuity of the point with a grayscale value of 255 in the row / column where the center point is located. This is because the coordinate values ​​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 ( Fig.12 ), while noise will cause the coordinate values ​​to mutate and cease to be continuous ( Fig.13). Therefore, this paper stipulates that when determining the start / end point of the image: if the coordinate spacing of the point with a gray 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. At this time, the segment with the largest number of coordinate points is selected as the target area to be segmented, and the two endpoints of the segment are determined as the start and end points of the segmentation.

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

[0025] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention 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 a grayscale image P. , ; S2. Use OTSU algorithm to find grayscale image P , The optimal threshold in the grayscale image P is , Divided into foreground area and background area; S3, confirming the optimal image center point of the foreground area using an improved image center selection method; 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 the end point of the segmentation; S5, judging whether there is a shadow in the foreground area, if yes, introducing a shadow detection mechanism, resetting the segmentation start and end points of the foreground area before segmentation; otherwise, directly segmenting; S6. Save the image and output it.

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 are used as central reference points. Then, the points on the vertical or horizontal axis where these four central reference points are located are thinned, and then the grayscale values ​​of the four row or column coordinate points are calculated, and the part greater than the optimal threshold is set to 255, and the part lower than the optimal threshold is set to 0. Finally, the number of coordinate points with a grayscale value of 255 is counted, and the row or column with the largest number is selected as the reference line, and the intersection of the row or column is used 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 plane rectangular coordinate system is established with the optimal center point as the origin. 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 point and end point of the segmentation; Secondly, the grayscale values ​​at different ordinates in the y-axis direction of the foreground area are analyzed, and the ordinate axis corresponding to the ordinate of the optimal center point and the grayscale value are used to establish a second coordinate system. The minimum ordinate corresponding to the point with a grayscale value of 255 in the foreground area is used as the dividing line. , The foreground area is segmented 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 point and end point of the segmentation.

4. The image adaptive segmentation algorithm based on improved edge detection according to claim 1, characterized in that: 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.

Citation Information

Patent Citations

  • Threshold segmentation method for USB surface defect detection

    CN111754538A

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

    EP4071665A1

  • Image processing apparatus, image processing method and medical image diagnostic apparatus

    JP2016016265A