An image segmentation algorithm based on watershed constraint and edge connection

Through the image segmentation algorithm based on watershed constraints and edge connections, the shortcomings of the edge segmentation method in continuity and enclosure are solved, and efficient image edge enclosed area extraction is achieved. It is suitable for a variety of environmental scenarios and provides good flexibility and feature basis.

CN115330821BActive Publication Date: 2025-07-25YANSHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing image segmentation algorithms have shortcomings in edge continuity and enclosure, especially the edge-based segmentation method cannot guarantee the continuity and enclosure of edges. The traditional method has a large amount of computation or is sensitive to noise, and deep learning methods require a large amount of computing resources.

Method used

The image segmentation algorithm based on watershed constraints and edge connections is adopted. By obtaining the initial edge map, hypersegmented edge map and broken edge search, the parallelized accelerated edge detection algorithm and mark-based watershed algorithm are used to combine the method of maximum local gradient to ensure the enclosure and continuity of the edges.

Benefits of technology

It quickly extracts the edges of closed areas in the image, improves the operating efficiency and flexibility of the algorithm, is suitable for a variety of environmental scenarios, and provides a feature basis for subsequent area merging and image recognition tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115330821B_ABST
    Figure CN115330821B_ABST
Patent Text Reader

Abstract

The present invention discloses an image segmentation algorithm based on watershed constraint and edge connection, belonging to the technical field of image segmentation in computer vision. This algorithm combines an edge detection algorithm and a watershed algorithm. The edge detection algorithm is used to obtain an initial edge map, and at the same time, it is parallelized. The marker-based watershed algorithm is used to obtain a super-segmented edge map. The breakpoints in the initial edge map are detected, distance connection is performed on the breakpoints and pseudo-breakpoints are removed. The breakpoints not on the super-segmented edge are updated on the super-segmented edge and used as the initial points for searching for broken edges. For the search of broken edges, the super-segmented edge is used as the search path, and broken edge connection is performed on the basis of the initial edge map. Finally, multiple closed edge contours are obtained, which is the segmentation result of the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image segmentation in computer vision, and particularly relates to an image segmentation algorithm based on watershed constraint and edge connection. Background Art

[0002] Image segmentation is one of the most fundamental problems in the field of computer vision and has extensive applications in many fields such as image recognition, object detection, medical diagnosis, and industrial quality inspection. Image segmentation divides an image into non-overlapping and meaningful sub-regions according to brightness, color, spatial texture, or geometric shape. The segmentation result has a very large impact on subsequent image processing. A good segmentation effect can make the subsequent work proceed smoothly.

[0003] Currently, image segmentation mainly includes methods based on threshold, edge, region, clustering, graph theory, and deep learning. The threshold-based segmentation method is simple to calculate and has high efficiency, but it is sensitive to noise and has low robustness. The clustering-based method can obtain a good segmentation effect, but this method takes too long and is not suitable for scenarios with high real-time requirements. The graph theory-based method can segment most images and achieve good results, but this method has a large amount of calculation and requires interactive implementation of segmentation. The edge-based segmentation method has accurate edge positioning and high speed, but this method cannot guarantee the continuity and closure of the edges. In recent years, with the development of convolutional neural networks, it has promoted the rapid development of the field of image segmentation and achieved satisfactory results. However, deep learning requires a large amount of computing power and a large number of sample trainings, so traditional image segmentation algorithms still need to be used in some specific scenarios.

[0004] To solve the problems existing in the edge-based segmentation method, many methods have been proposed to solve this problem. For example, an edge detection algorithm based on edge continuity uses the ant colony algorithm for edge connection; a fast image segmentation algorithm based entirely on edge information proposes a four-way scanning region filling algorithm to completely extract meaningful objects from the edge map; other algorithms such as the Hough transform, morphological method, curve fitting, etc. Although the above algorithms can connect broken edges, they cannot guarantee that the obtained edges are the real edges existing in the original image.

[0005] In the existing image segmentation algorithms, the watershed algorithm has a good response to weak edges and the region boundary belongs to a single-pixel chain. The boundary of the over-segmented region obtained by the watershed algorithm can completely retain most of the weak edge and strong edge information in the original image. Summary of the Invention

[0006] The object of the present invention is to overcome the deficiencies of the prior art and provide an image segmentation algorithm based on watershed constraint and edge connection, which can quickly extract edge-closed regions in an image, is applicable to a variety of environmental scenarios, has good flexibility and portability, and provides a feature basis for subsequent region merging and image recognition tasks.

[0007] The technical problem proposed by the present invention is solved as follows:

[0008] An image segmentation algorithm based on watershed constraint and edge connection, comprising the following steps:

[0009] Step 1: Obtain an initial edge map. Convert the RGB color image into a grayscale image, perform Gaussian filtering on it, and use an edge detection algorithm with parallelization acceleration to obtain the initial edge map;

[0010] Step 2: Obtain a super-segmented edge map. Utilize the gradient magnitude map to calculate the marker points required for the watershed algorithm, use the image after Gaussian filtering as the input image, obtain the super-segmented effect diagram using the marker-based watershed algorithm, and convert it into a single channel to obtain the super-segmented edge map;

[0011] Step 3: Determine the initial search points for broken edges. It is characterized in that breakpoint detection is performed on the initial edge map obtained in Step 1. If the distance between breakpoints is less than the set threshold, distance connection is performed on them. Then, a pseudo-breakpoint removal operation is carried out, and breakpoint detection is performed again. Utilize the super-segmented edge map obtained in Step 2 to update the breakpoints not on the super-segmented edge onto the super-segmented edge according to the method of local connection. All breakpoints are used as the initial points for edge search.

[0012] Step 4: Search for broken edges and obtain an edge-closed contour. Use the breakpoints obtained in Step 3 as the search starting points, use the super-segmented edge map obtained in Step 2 as the search path, and adopt the method of maximum local gradient for search. After all breakpoints are searched, iterative search is carried out until the termination condition is reached to obtain a complete edge contour, and thus the edge segmentation effect is obtained.

[0013] Furthermore, Step 1 specifically includes the following steps:

[0014] Step 1.1: Convert the RGB color image into a gray image:

[0015] Step 1.2: Perform Gaussian filtering on the gray image:

[0016] Step 1.3: Calculate the gradient magnitude map and edge direction map of the filtered image:

[0017] Step 1.4: Obtain an anchor point map according to the gradient magnitude map and edge direction map:

[0018] Step 1.5: Connect the anchor points to obtain the initial edge map.

[0019] Furthermore, the specific steps of Step 2 are as follows:

[0020] Step 2.1: Obtain the marker points required for the watershed algorithm:

[0021] By using the gradient map G[x, y], the local maximum points of the entire image are used as marker points. Taking the pixel point (x i , y i ) as the center, compare its pixel gradient amplitude with that of the pixels in its eight-neighborhood. If the gradient amplitude of this point is greater than that of other pixel points, then this point is used as a marker point.

[0022]

[0023] Among them, i -> p represents the eight-neighborhood pixel point p of pixel point i, (p = 1, 2,... 8). Mark[x, y] represents the marker map.

[0024] Step 2.2: Obtain the super-segmentation edge map:

[0025] Convert the Gaussian-filtered image into a three-channel image as the input image. Using the marker points obtained in Step 2.1, use the watershed algorithm to obtain the super-segmentation edge map and convert it into a single-channel map.

[0026] Furthermore, the specific steps of Step 3 are as follows:

[0027] Step 3.1: Breakpoint detection:

[0028] The main method of breakpoint detection is to first set the edge pixel value to 255 and the background value to 0, and then traverse the initial edge map to count the number N of pixels adjacent to the edge in the eight-neighborhood of each pixel. If N ≤ 1, then this pixel point is a breakpoint.

[0029]

[0030] Among them, N represents the number of pixels adjacent to the edge, eMap[x i->p , y i->p is the pixel value of pixel point x, and p is the p-th neighborhood of the eight-neighborhood;

[0031] Step 3.2: Breakpoint distance connection:

[0032] According to the breakpoints obtained in Step 3.1, set a distance threshold, calculate the distance between every two breakpoints, and connect the breakpoints that meet the threshold with a straight line.

[0033] d = |x1 - x2| + |y1 - y2|

[0034]

[0035] Among them, d represents the distance between two breakpoints, and k represents the breakpoint distance threshold.

[0036] Step 3.3: Remove false breakpoints:

[0037] Before determining the initial edge search points, it is necessary to remove the false breakpoints existing in the breakpoints. The main method is to set the values at all breakpoint positions to 0 and re-detect the breakpoints in the edge map. This will remove the false breakpoints and update the breakpoints at other positions to the adjacent edge points at the same time.

[0038] eMap[x i ,y i = 0, (x i ,y i ) ∈ BP[(x b1 ,y b1 ),(x b2 ,y b2 )…(x bn ,y bn )]

[0039] Among them, BP represents the set of breakpoints, and eMap[x i ,y i represents the edge pixel value of the pixel point (x i ,y i );

[0040] Step 3.4: Update all breakpoints to the super-segmentation edge:

[0041] The main method is to first determine whether the current breakpoint is on the super-segmentation edge. If it is not on the super-segmentation edge, in the eight-neighborhood centered on the breakpoint, first determine the positions of the adjacent edge points to the breakpoint, and then find the three pixel points symmetric to it with respect to the breakpoint. The point with the maximum gradient is used as the new breakpoint until all breakpoints are updated to the super-segmentation edge.

[0042] Through the above steps, the initial positions of the edge search can be obtained.

[0043] Furthermore, the specific steps of the said step 4 include the following steps:

[0044] Step 4.1: Search for broken edges on the super-segmentation edge:

[0045] If it is assumed that the edge direction D[x b ,y b = 0 (horizontal direction) of the b-th breakpoint, that is, the initial search path is in the horizontal direction. First, determine whether the adjacent edge pixel of this breakpoint is located at (x b -1,yb -1),(x b -1,y b ),(x b -1,y b +1), find (x b ,y b -1), (x b +1,y b -1), (x b +1,y b ), (x b +1,y b +1), (x b ,y b +1) existing over-segmented edge pixels, select the neighborhood pixel point with the maximum gradient magnitude. If this pixel point does not belong to the edge pixels, add it to the edge pixel set and use it as a new search starting point. If the edge pixel adjacent to this breakpoint is located at (x b +1,y b -1), (x b +1,y b ), (x b +1,y b +1), then search (x b ,y b -1), (x b -1,y b -1), (x b -1,y b ), (x b -1,y b +1), (x b ,y b +1), and repeat the above operations. If the edge direction of the current breakpoint is vertical, first judge whether the edge pixel adjacent to this breakpoint is located at (x b -1,y b -1), (x b ,y b -1), (x b +1,y b -1), find (x b -1,y b ), (x b -1,y b +1), (x b ,y b +1), (x b +1,y b +1), (x b +1,y b ), and select the neighborhood pixel point with the maximum gradient magnitude as the new search point. If the edge pixel adjacent to this breakpoint is located at (x b-1, y b +1), (x b , y b +1), (x b +1, y b +1), then search (x b -1, y b ), (x b -1, y b -1), (x b , y b -1), (x b +1, y b -1), (x b +1, y b ), and repeat the above operations. Repeat the above operations. Continue the search from the new search point until the number of breakpoints remains unchanged.

[0046] Step 4.2: Reverse the direction of the new breakpoint positions:

[0047] After all breakpoints have been searched, perform breakpoint detection on the generated edge map again. There will still be a part of breakpoints. Due to the constraint of the edge direction for this part of breakpoints, perform a direction reversal operation and re-perform edge search.

[0048] Step 4.3: Repeat Step 4.1 and Step 4.2 until the number of breakpoints is equal to the number of breakpoints in the previous search, then stop the search, and finally obtain a complete closed edge contour.

[0049] Due to the adoption of the above technical solution, the beneficial effects of the present invention are as follows:

[0050] 1. Use the EDrawing algorithm to extract high-quality edge chains in the image and parallelize and accelerate it, improving the running efficiency of the algorithm and providing the initial edge information of the image at the same time.

[0051] 2. Use the marker-based watershed algorithm to obtain a super-segmented edge map containing weak edge information, providing a search path for the search of broken edges and ensuring the effectiveness of edge search.

[0052] 3. Define breakpoints and propose a search strategy, propose to search for broken edges from the breakpoint positions, use the super-segmented edge map as the path map of the broken edges, and use the characteristic of higher gradient in the edge part to perform edge search to obtain a closed edge contour, and then obtain the image segmentation effect. Description of the Drawings

[0053] Figure 1 is the flowchart of the algorithm described in the present invention;

[0054] Figure 2 is the schematic diagram of the effect of initial edge detection;

[0055] Figure 3 Schematic diagram of the effect of the super-segmented edge;

[0056] Figure 4 Schematic diagram of the complete edge;

[0057] Figure 5 CUDA acceleration flow chart;

[0058] Figure 6 Schematic diagram of the break point;

[0059] Figure 7 Schematic diagram of the break point distance connection;

[0060] Figure 8 Schematic diagram of the pseudo break point;

[0061] Figure 9 Schematic diagram of the break point update on the super-segmented edge;

[0062] Figure 10 Schematic diagram of the edge search;

[0063] Figure 11 Original image of the building scene;

[0064] Figure 12 Schematic diagram of the building scene segmentation;

[0065] Figure 13 Original image of the indoor scene;

[0066] Figure 14 Schematic diagram of the indoor scene segmentation. Detailed implementation method

[0067] Next, according to the attached Figures 1-14 The specific implementation method of the present invention will be further described.

[0068] This embodiment provides an image segmentation algorithm based on watershed constraint and edge connection. Its flow chart is as Figure 1 shown. First, perform initial edge detection on the image to obtain preliminary edge information, then use the watershed algorithm to obtain the super-segmented edge path search graph, and finally perform broken edge connection to obtain a closed edge contour, thereby obtaining an accurate segmentation result, including the following steps:

[0069] Step 1: Input the RGB image and use the EDrawing algorithm to obtain the initial edge image.

[0070] Step 1.1: Grayscale the input RGB image. Using the weighted average method, the three channels are weighted and averaged according to different weights to calculate the grayscale value corresponding to each pixel. The grayscale value gray of each pixel can be obtained from the formula:

[0071] gray = R * 0.299 + G * 0.587 + B * 0.114

[0072] Among them, R, G, and B respectively represent the red component, green component, and blue component in the RGB color space.

[0073] Traversing all pixels can obtain the grayscale image corresponding to the input RGB image.

[0074] Step 1.2: Use a Gaussian kernel with a size of 5×5 and a standard deviation of δ = 1 to perform filtering and smoothing on the grayscale image.

[0075]

[0076] Gauss[x, y] = gray[x, y] * H[x, y]

[0077] Among them, (x, y) represents the pixel point, gray[x, y] represents the grayscale image, H[x, y] represents the Gaussian filter, and Gauss[x, y] represents the filtered image.

[0078] Step 1.3: Calculate the gradient magnitude map and edge direction map of the filtered image:

[0079] Based on the Gaussian-filtered image, use the Sobel operator to calculate the horizontal gradient and vertical gradient G of each pixel respectively y and the gradient magnitude G.

[0080]

[0081]

[0082] G[x, y] = |G x | + |G y |

[0083] Among them, G x is the horizontal gradient, G y is the vertical gradient. Traversing all pixels in the image can obtain the pixel gradient magnitude map of the image.

[0084] At the same time, by comparing the horizontal gradient G of each pixel x and the vertical gradient G y . If |G x | ≤ |G y |, it is considered that the edge direction of this pixel is the horizontal direction. If |G x | > |G y |, it is considered that the direction of this pixel point is the vertical direction. Traversing all pixels in the image can obtain the edge direction map.

[0085]

[0086] Among them, D[x, y] represents the edge direction map.

[0087] Step 1.4: Obtain the anchor point map according to the gradient magnitude map and the edge direction map:

[0088] Assume that the current pixel is in the horizontal direction. Then compare the two adjacent pixels above and below it. If the difference between the gradient magnitude of the current pixel and the gradient magnitudes of the two adjacent pixels above and below it is greater than or equal to the anchor point threshold, then this pixel is an anchor point. If this pixel is in the vertical direction, then compare the two adjacent pixels on the left and right.

[0089]

[0090] Among them, aMap[x, y] represents the anchor point map, and Th anchor represents the anchor point threshold.

[0091] By performing the above operations by traversing all pixels in the entire image, the anchor point image can be obtained.

[0092] Step 1.5: Connect the anchor points and draw the initial edge map eMap:

[0093] First, initialize the edge chain set E = {e1, e2,..., e m} = 0. Search for the 8-neighborhood pixels of any anchor point (x i , y i ). If the edge direction of the current anchor point pixel is in the horizontal direction, that is, the initial search path is in the horizontal direction, then search the 6 horizontal neighborhood pixels on the left and right. First, search (x i - 1, y i - 1), (x i - 1, y i ), and (x i - 1, y i + 1). Then judge the maximum value among G[x i - 1, y i - 1], G[x i - 1, y i , and G[x i - 1, y i + 1]. Select the pixel with the largest gradient magnitude among them. If this pixel is not in the edge pixel set, then add it to the edge pixel set and use it as a new search point to repeat the above steps. If there is no point that meets the search conditions, then search (x i + 1, y i - 1), (x i + 1, y i ), and (x i + 1, yi +1), repeat the above steps. If the edge direction of the current anchor pixel is vertical, i.e., the initial search path is vertical, then search the six vertical neighborhoods above and below. First, search (x i -1, y i +1), (x i , y i +1) and (x i +1, y i +1), then judge the maximum value among G[x i -1, y i +1], G[x i , y i +1] and G[x i +1, y i +1], select the pixel point with the largest gradient magnitude among them. If the pixel point is not in the edge pixel set, add it to the edge pixel set and use it as a new search point to repeat the above steps. If there is no point that meets the search conditions, search (x i -1, y i -1), (x i , y i -1) and (x i +1, y i -1), and repeat the above steps. Repeat the above steps for all anchor points to obtain a series of single-pixel edge chains E. That is, the initial edge map is obtained.

[0094] Step 2: Obtain the over-segmented edge map. Using the gradient magnitude map obtained by the Sobel operator, calculate the marker points required for the watershed algorithm. Take the image after Gaussian filtering as the input image, use the marker-based watershed algorithm to obtain the over-segmented effect diagram, and convert it to a single channel to obtain the over-segmented edge map;

[0095] Step 2.1: Calculate the marker points required for the watershed algorithm:

[0096] By using the gradient map G(x, y), take the local maximum points of the entire image as marker points. Taking the pixel point (x, y) as the center, compare its gradient magnitude with that of the pixels in its eight neighborhoods. If the gradient magnitude of this point is greater than that of other pixel points, then take this point as a marker point.

[0097]

[0098] Among them, i->p represents the eight-neighborhood pixel point p of pixel point i, (p = 1, 2,... 8). Mark[x, y] represents the marker map.

[0099] Step 2.2: Obtain the over-segmented edge map:

[0100] Convert the image after Gaussian filtering into a three-channel image as the input image. Using the marked points obtained in Step 2.1, obtain the super-segmentation edge map using the watershed algorithm and convert it into a single-channel map.

[0101] wMap[x,y] = cvtColor(Watershed(Gauss[x,y],Mark[x,y]), BGR2GRAY)

[0102] Among them, wMap[x,y] represents the super-segmentation edge map, cvtColor(f[x,y], BGR2GRAY) means converting the three-channel map f[x,y] into a single channel, and Watershed() represents the watershed processing.

[0103] Step 3: Determine the initial search points for the broken edges. Perform break point detection on the initial edge map obtained in Step 1. If the distance between break points is less than the set threshold, perform distance connection on them. Then perform the operation of removing pseudo break points and re-perform break point detection. Using the super-segmentation edge map obtained in Step 2, update the break points that are not on the super-segmentation edge to the super-segmentation edge according to the method of local connection. Take all break points as the initial points for edge search.

[0104] Step 3.1: Obtain the break points in the initial edge map:

[0105] The existence of break points indicates that there is a break phenomenon in the edge, and the break points are also the starting points for searching for broken edges. The main method for break point detection is to first set the edge pixel value to 255 and the background to 0, and then traverse the initial edge map to count the number N of pixels adjacent to the edge in the eight-neighborhood of each pixel. If N ≤ 1, then this pixel point is a break point.

[0106]

[0107] Among them, N represents the number of pixels adjacent to the edge, eMap[x i->p ,y i->p is the pixel value of pixel point x, and p is the p-th neighborhood in the eight-neighborhood.

[0108] Step 3.2: Distance connection of break points:

[0109] For the obtained break points, set a distance threshold, calculate the distance between every two break points, and connect the break points that meet the threshold with a straight line. The distance threshold is set to 4.

[0110] d = |x1 - x2| + |y1 - y2|

[0111]

[0112] Among them, d represents the distance between two break points, and k represents the break point distance threshold.

[0113] Step 3.3: Remove pseudo-breakpoints:

[0114] Before determining the initial edge search points, it is necessary to remove the pseudo-breakpoints existing in the breakpoints. The main method is to set the values at all breakpoint positions to 0 and re-detect the breakpoints in the edge map. This will remove the pseudo-breakpoints and update the breakpoints at other positions to the adjacent edge points at the same time.

[0115] eMap[x i ,y i = 0, (x i ,y i ) ∈ BP[(x b1 ,y b1 ), (x b2 ,y b2 )…(x bn ,y bn )]

[0116] Among them, BP represents the breakpoint set. eMap[x i ,y i represents the edge pixel value of the pixel point (x i ,y i ).

[0117] Step 3.4: Update all breakpoints to the super-segmentation edge:

[0118] To make the initial search points search along the super-segmentation edge, it is necessary to ensure that all breakpoint positions are on the super-segmentation edge. The main method is to first judge whether the current breakpoint is on the super-segmentation edge. If it is not on the super-segmentation edge, for the eight-neighborhood centered on the breakpoint, first judge the positions of the adjacent edge points to the breakpoint, and then find the point with the maximum gradient among the three symmetric pixel points and update it to the new breakpoint until the breakpoint is updated to the super-segmentation edge.

[0119] If the current breakpoint is assumed to be (x b ,y b ), and the adjacent edge point to it is (x b ,y b -1), judge the point with the maximum gradient among G[x b -1,y b +1], G[x b ,y b +1], G[x b +1,y b +1] and update it to the new breakpoint; if the adjacent edge point to the breakpoint is (x b ,y b +1), then judge G[x b -1,yb , G[x b , y b , G[x b + 1, y b - 1]; If the edge point adjacent to the break point is (x b - 1, y b - 1), then judge G[x b + 1, y b , G[x b , y b + 1], G[x b + 1, y b + 1]; If the edge point adjacent to the break point is (x b + 1, y b + 1), then judge G[x b - 1, y b , G[x b - 1, y b - 1], G[x b , y b - 1]; The edge points adjacent to the break point are located at (x b + 1, y b ), (x b - 1, y b ), (x b - 1, y b + 1), (x b + 1, y b - 1), and so on. Repeat the above steps until the break point is updated to the super-segmentation edge.

[0120] Through the above steps, the initial position of the edge search can be obtained.

[0121] Step 4: Search for the broken edge and obtain the closed edge contour. Take the break point obtained in Step 3 as the starting point of the search, take the super-segmentation edge map obtained in Step 2 as the search path, and use the method of the maximum local gradient for the search. After all break points are searched, perform iterative search until the termination condition is reached to obtain the complete edge contour, and then obtain the edge segmentation effect.

[0122] Taking the break point (x i , y i ) as the center, its eight-neighborhood is used as the local search window. The specific steps are as follows:

[0123] Step 4.1: Search for the broken edge:

[0124] If it is assumed that the edge direction D[x b , y b= 0 (horizontal direction), that is, the initial search path is horizontal. First, judge whether the edge pixels adjacent to this breakpoint are located at (x b - 1, y b - 1), (x b - 1, y b ), (x b - 1, y b + 1), and find out the super-segmented edge pixels existing in (x b , y b - 1), (x b + 1, y b - 1), (x b + 1, y b ), (x b + 1, y b + 1), (x b , y b + 1). Select the neighborhood pixel point with the largest gradient magnitude. If this pixel point does not belong to the edge pixel, add it to the edge pixel set and use it as the new search starting point. If the edge pixels adjacent to this breakpoint are located at (x b + 1, y b - 1), (x b + 1, y b ), (x b + 1, y b + 1), then search for (x b , y b - 1), (x b - 1, y b - 1), (x b - 1, y b ), (x b - 1, y b + 1), (x b , y b + 1), and repeat the above operations. If the edge direction of the current breakpoint is vertical, first judge whether the edge pixels adjacent to this breakpoint are located at (x b - 1, y b - 1), (x b , y b - 1), (x b + 1, y b - 1), and find out (x b - 1, y b ), (x b - 1, y b + 1), (x b , y b + 1), (x b + 1, y b + 1), (x b + 1, y b)For the existing super-segmented edge pixels, select the neighborhood pixel with the largest gradient magnitude as the new search point. If the edge pixels adjacent to this break point are located at (x b -1, y b +1), (x b , y b +1), (x b +1, y b +1), then search for (x b -1, y b ), (x b -1, y b -1), (x b , y b -1), (x b +1, y b -1), (x b +1, y b ), and repeat the above operations. Repeat the above operations. Continue the search from the new search point until the number of break points remains unchanged.

[0125] Step 4.2: After all break points have been searched, perform break point detection on the generated edge map again, reverse the edge direction at each break point position, and conduct a new round of search.

[0126] Step 4.3: Repeat Step 4.1 and Step 4.2 until the number of break points is equal to the number of break points in the previous search, and then stop the search to finally obtain a complete closed edge contour.

[0127] The present invention extracts edge information in the image, finds the broken edges between the edges, thereby obtaining a closed edge contour, and further obtaining an image segmentation effect. It is mainly applied to the fields of image recognition, medical image processing, and industrial quality inspection. For a schematic diagram of the segmentation effect using the method of the present invention, see Figures 11 to 14 .

[0128] The above-described embodiments are only described as the preferred embodiments of the present invention, and do not limit the scope of the present invention. Without departing from the design spirit of the present invention, various deformations and improvements made by those of ordinary skill in the art to the technical solutions of the present invention shall fall within the protection scope determined by the claims of the present invention.

Claims

1. An image segmentation algorithm based on watershed constraint and edge connection, characterized in that It includes the following steps: Step 1: Obtain the initial edge map; convert the RGB color image into a grayscale image, perform Gaussian filtering on it, and use the edge detection algorithm with parallel acceleration to obtain the initial edge map; Step 2: Obtain the over-segmented edge map; use the gradient magnitude map to calculate the marker points required for the watershed algorithm, take the image after Gaussian filtering as the input image, use the marker-based watershed algorithm to obtain the over-segmented effect diagram, and convert it into a single channel to obtain the over-segmented edge map; Step 3: Determine the initial points for searching for broken edges; perform breakpoint detection on the initial edge map obtained in Step 1. If the distance between breakpoints is less than the set threshold, perform distance connection on them, then perform the operation of removing pseudo-breakpoints and re-perform breakpoint detection; use the over-segmented edge map obtained in Step 2 to update the breakpoints that are not on the over-segmented edge to the over-segmented edge according to the method of local connection, and use all breakpoints as the initial points for edge searching; Update all breakpoints to the over-segmented edge: First, judge whether the current breakpoint is on the over-segmented edge. If it is not on the over-segmented edge, in the eight-neighborhood centered on the breakpoint, first judge the position of the edge points adjacent to the breakpoint, and then find the three pixel points symmetric to it about the breakpoint. The point with the maximum gradient is used as the new breakpoint until the breakpoint is updated to the over-segmented edge; Step 4: Search for broken edges and obtain the closed edge contour; use the breakpoints obtained in Step 3 as the starting points for searching, use the over-segmented edge map obtained in Step 2 as the search path, adopt the method of local gradient maximum for searching, finish searching for the breakpoints, perform iterative searching, and finally reach the termination condition to obtain the complete edge contour, thereby obtaining the effect of edge segmentation; The specific steps of Step 4 include the following steps: Step 4.1: Search for broken edges on the over-segmented edge. After all breakpoints are searched, perform breakpoint detection on the generated edge map again, and there will still be a part of new breakpoints; The specific method of searching for broken edges on the over-segmented edge in Step 4.1 is: If it is assumed that the edge direction D[x b , y b = 0, which is the horizontal direction, that is, the initial search path is the horizontal direction. First, judge whether the edge pixels adjacent to this breakpoint are located at (x b - 1, y b - 1), (x b - 1, y b ), (x b - 1, y b + 1), and find out the over-segmented edge pixels existing in (x b , y b - 1), (x b + 1, y b - 1), (x b + 1, y b ), (x b + 1, y b + 1), (x b , y b + 1). Select the neighborhood pixel point with the largest gradient magnitude. If this pixel point does not belong to the edge pixel, add it to the edge pixel set and use it as the new search starting point; if the edge pixel adjacent to this breakpoint is located at (x b + 1, y b - 1), (x b + 1, y b ), (x b + 1, y b + 1), then search for (x b , y b - 1), (x b - 1, y b - 1), (x b - 1, y b ), (x b - 1, y b + 1), (x b , y b + 1), and repeat the above operations; if the edge direction of the current breakpoint is the vertical direction, first judge whether the edge pixels adjacent to this breakpoint are located at (x b - 1, y b - 1), (x b , y b - 1), (x b + 1, y b - 1), and find out (x b - 1, y b ), (x b - 1, y b + 1), (x b , y b + 1), (x b + 1, y b +1), (x b +1, y b ) existing super-segmented edge pixels, select the neighborhood pixel with the maximum gradient magnitude as the new search point; if the edge pixel adjacent to this break point is located at (x b -1, y b +1), (x b , y b +1), (x b +1, y b +1), then search (x b -1, y b ), (x b -1, y b -1), (x b , y b -1), (x b +1, y b -1), (x b +1, y b ), repeat the above operation, continue the search from the new search point until the number of break points remains unchanged; Step 4.2: Reverse the direction of the new breakpoint positions: Since this part of the breakpoints is restricted by the edge direction, perform the operation of reversing the direction and re-perform edge searching; Step 4.3: Repeat the above Steps 4.1 and 4.2 until the number of breakpoints does not change and stop searching. Finally, obtain the complete closed edge contour, that is, obtain the effect of image segmentation.

2. The image segmentation algorithm based on watershed constraint and edge connection according to claim 1, characterized in that The specific steps of Step 1 include the following steps: Step 1.1: Convert the RGB color image into a gray image: Step 1.2: Perform Gaussian filtering on the gray image: Step 1.3: Calculate the gradient magnitude map and edge direction map of the filtered image: Step 1.4: Obtain the anchor point map according to the gradient magnitude map and edge direction map: Step 1.5: Connect the anchor points to obtain the initial edge map.

3. The image segmentation algorithm based on watershed constraint and edge connection according to claim 1, wherein The specific steps of Step 2 include the following steps: Step 2.1: Obtain the marker points required for the watershed algorithm: By utilizing the gradient map G[x, y], the local maximum points of the entire image are used as marker points. Taking the pixel point (x i , y i ) as the center, its pixel gradient magnitude is compared with that of the eight neighboring pixels. If the gradient magnitude of this point is greater than that of other pixel points, then this point is used as a marker point; Among them, i->p represents the eight-neighborhood pixel point p of pixel point i, (p = 1, 2,... 8), and Mark[x, y] represents the marker map; Step 2.2: Obtain the over-segmented edge map: First, convert the image after Gaussian filtering into a three-channel image as the input image. Using the marked points obtained in Step 2.1, the super-segmentation edge map is obtained by using the watershed algorithm and converted into a single-channel map; wMap[x,y] = cvtColor(Watershed(Gauss[x,y],Mark[x,y]),BGR2GRAY) where wMap[x,y] represents the super-segmentation edge map, cvtColor(f[x,y],BGR2GRAY) means converting the three-channel map f[x,y] into a single channel, and Watershed() represents the watershed processing.

4. A method for segmenting an image based on watershed constraint and edge connection according to claim 1, characterized in that Step 3 specifically includes the following steps: Step 3.1: Breakpoint detection: First, set the edge pixel value to 255 and the background value to 0. Then traverse the initial edge map and count the number N of adjacent pixels to the edge pixels in the eight-neighborhood of the current pixel i. If N ≤ 1, the current pixel point is a breakpoint; where N represents the number of pixels adjacent to the edge, eMap[x i->p ,y i->p is the pixel value of pixel point x, and p is the p-th neighborhood in the eight-neighborhood; Step 3.2: Breakpoint distance connection: For the obtained breakpoints, set a distance threshold, calculate the distance between every two breakpoints, and the breakpoints within the threshold are connected by a straight line; d = |x1 - x2| + |y1 - y2| where d represents the distance between two breakpoints and k represents the breakpoint distance threshold; Step 3.3: Remove false breakpoints: Before determining the initial search point of the edge, it is necessary to remove the false breakpoints among the breakpoints. The main method is to set the edge pixel values at all breakpoint positions to 0, re-detect the breakpoints in the edge map, which will remove the false breakpoints and update the breakpoints at other positions to the edge points adjacent to them; eMap[x i ,y i = 0, (x i ,y i ) ∈ BP[(x b1 ,y b1 ), (x b2 ,y b2 )…(x bn ,y bn )] Among them, BP represents the breakpoint set, and eMap[x i , y i represents the edge pixel value of the pixel point (x i , y i ).

5. An image segmentation algorithm based on watershed constraint and edge connection according to claim 4, characterized in that: The specific method of updating all breakpoints to the super-segmentation edge in Step 3 is as follows: Assume the current breakpoint is (x b , y b ), and the adjacent edge point is (x b , y b - 1). Judge the maximum gradient points of G[x b - 1, y b + 1], G[x b , y b + 1], G[x b + 1, y b + 1], and update it as the new breakpoint; if the adjacent edge point to the breakpoint is (x b , y b + 1), then judge G[x b - 1, y b - 1], G[x b , y b - 1], G[x b + 1, y b - 1]; if the adjacent edge point to the breakpoint is (x b - 1, y b - 1), then judge G[x b + 1, y b , G[x b , y b + 1], G[x b + 1, y b + 1]; If the edge point adjacent to the break point is (x b + 1, y b + 1), then judge G[x b - 1, y b , G[x b - 1, y b - 1], G[x b , y b - 1]; the edge points adjacent to the break point are located at (x b + 1, y b ), (x b - 1, y b ), (x b - 1, y b + 1), (x b + 1, y b - 1), and repeat the above steps until the break point is updated to the super-segmentation edge.