CN115330821A - Image segmentation algorithm based on watershed constraint and edge connection - Google Patents

Image segmentation algorithm based on watershed constraint and edge connection Download PDF

Info

Publication number
CN115330821A
CN115330821A CN202210893472.9A CN202210893472A CN115330821A CN 115330821 A CN115330821 A CN 115330821A CN 202210893472 A CN202210893472 A CN 202210893472A CN 115330821 A CN115330821 A CN 115330821A
Authority
CN
China
Prior art keywords
edge
point
image
breakpoint
segmentation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210893472.9A
Other languages
Chinese (zh)
Inventor
丁伟利
张志鹏
杨韬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yanshan University
Original Assignee
Yanshan University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yanshan University filed Critical Yanshan University
Priority to CN202210893472.9A priority Critical patent/CN115330821A/en
Publication of CN115330821A publication Critical patent/CN115330821A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/12Edge-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/155Segmentation; Edge detection involving morphological operators
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/181Segmentation; Edge detection involving edge growing; involving edge linking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10024Color image
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20112Image segmentation details
    • G06T2207/20152Watershed segmentation

Abstract

The invention discloses an image segmentation algorithm based on watershed constraint and edge connection, which belongs to the technical field of image segmentation in computer vision. And for the search of the fracture edge, the super-segmentation edge is used as a search path, the fracture edge is connected on the basis of the initial edge image, and finally a plurality of closed edge contours are obtained, namely the segmentation result of the image is obtained.

Description

Image segmentation algorithm based on watershed constraint and edge connection
Technical Field
The 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
Image segmentation is one of the most basic problems in the field of computer vision, and has wide application in many fields such as image recognition, target detection, medical diagnosis, industrial quality inspection and the like. The image segmentation divides the image into sub-regions which are mutually not intersected and are meaningful according to the brightness, the color, the spatial texture or the geometric shape, the segmentation result has great influence on the subsequent image processing, and the segmentation effect is good, so that the subsequent work can be smoothly carried out.
At present, the image segmentation mainly comprises methods based on threshold values, edges, regions, clusters, graph theory and deep learning. The threshold-based segmentation method is simple in calculation and high in efficiency, but is sensitive to noise and low in robustness. The clustering-based method can obtain good segmentation effect, but the method is too long in time consumption and is not suitable for scenes with high real-time requirements. The method based on graph theory can segment most images and achieve good effect, but the method has large calculation amount and needs interaction to realize segmentation. The edge-based segmentation method has accurate edge positioning and high speed, but the method cannot ensure the continuity and the closure of the edge. In recent years, with the development of a convolutional neural network, the rapid development of the image segmentation field is promoted, and a satisfactory effect is achieved, but deep learning requires a large computing power and a large amount of sample training, so that a traditional image segmentation algorithm is required to be used in some specific scenes.
The method aims to solve the problems existing in the edge segmentation method. A number of approaches have been proposed to address this problem. For example, an edge detection algorithm based on edge continuity adopts an ant colony algorithm to perform edge connection; a four-way scanning area filling algorithm is proposed to completely extract a meaningful object from an edge image based on a rapid image segmentation algorithm of edge information; other algorithms such as Hough transforms, morphological methods, curve fitting, etc. Although the above algorithm can connect the broken edges, it cannot guarantee that the obtained edges are the edges actually existing in the original image.
In existing image segmentation algorithms, the watershed algorithm responds well to weak edges and the region boundaries belong to a single pixel chain. The super-segmentation region boundary obtained by the watershed algorithm can completely reserve most of weak edge and strong edge information in the original image.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides an image segmentation algorithm based on watershed constraint and edge connection, which can quickly extract an edge closed region in an image, is suitable for various environmental scenes, has better flexibility and portability, and provides a characteristic basis for subsequent region merging and image recognition tasks.
The technical problem proposed by the invention is solved as follows:
an image segmentation algorithm based on watershed constraint and edge connection comprises the following steps:
step 1: an initial edge map is obtained. Converting the RGB color image into a gray image, performing Gaussian filtering on the gray image, and obtaining an initial edge image by using an edge detection algorithm after parallelization acceleration;
step 2: and acquiring a super-segmentation edge map. Calculating mark points required by a watershed algorithm by using the gradient magnitude image, taking the image after Gaussian filtering as an input image, obtaining a super-segmentation effect image by using the watershed algorithm based on the mark, and converting the super-segmentation effect image into a single channel to obtain a super-segmentation edge image;
and step 3: determining a search initiation point of the fracture edge. The method is characterized in that the initial edge graph obtained in the step 1 is subjected to breakpoint detection. And if the distance between the breakpoints is smaller than the set threshold value, performing distance connection on the breakpoints. And then carrying out pseudo breakpoint removing operation and carrying out breakpoint detection again. And (3) obtaining a super-segmentation edge graph by utilizing the step 2, and updating the break points which are not positioned on the super-segmentation edge according to a local connection method. All break points are used as initial points for edge search.
And 4, step 4: and searching for a broken edge to obtain an edge closed contour. And (3) taking the breakpoint obtained in the step (3) as a search starting point, taking the super-segmentation edge graph obtained in the step (2) as a search path, searching by adopting a method with the maximum local gradient, and after all breakpoints are searched, carrying out iterative search to finally obtain a complete edge profile under a termination condition so as to obtain an edge segmentation effect.
Further, the step 1 specifically includes the following steps:
step 1.1: converting the RGB color image into a gray image:
step 1.2: the gray image is gaussian filtered:
step 1.3: calculating a gradient amplitude map and an edge directional diagram of the filtered image:
step 1.4: acquiring an anchor point diagram according to the gradient amplitude diagram and the edge directional diagram:
step 1.5: and connecting anchor points to obtain an initial edge map.
Further, the step 2 specifically includes the following steps:
step 2.1: obtaining the mark points required by the watershed algorithm:
by using a gradient map G [ x, y ]]And taking the local maximum point of the whole image as a marking point. By pixel point (x) i ,y i ) And if the gradient amplitude of the point is larger than that of other pixel points, the point is taken as a mark point.
Figure BDA0003768473890000031
Wherein i- > p represents eight neighborhood pixel points p of pixel point i, (p =1,2, \ 8230; 8). Mark [ x, y ] represents a Mark map.
Step 2.2: acquiring a super-segmentation edge map:
and (3) converting the image subjected to Gaussian filtering into a three-channel image as an input image, obtaining a super-segmentation edge map by using the mark points obtained in the step (2.1) and a watershed algorithm, and converting the super-segmentation edge map into a single-channel map.
Further, the step 3 specifically includes the following steps:
step 3.1: breakpoint detection:
the main method of breakpoint detection is firstly to make the edge pixel value 255 and the background value 0, then traverse the initial edge graph, count the number N of pixels adjacent to the edge in the eight neighborhoods of each pixel, if N is less than or equal to 1, then the pixel point is a breakpoint.
Figure BDA0003768473890000032
Where N represents the number of pixels adjacent to the edge, eMap [ x ] i->p ,y i->p ]The pixel value of the pixel point x is shown, and p is the pth neighborhood of the eight neighborhoods;
step 3.2: connecting breakpoint distance:
and 3.1, setting a distance threshold according to the breakpoints obtained in the step 3.1, calculating the distance between every two breakpoints, and performing linear connection on the breakpoints meeting the requirement within the threshold.
d=|x 1 -x 2 |+|y 1 -y 2 |
Figure BDA0003768473890000041
Where d represents the distance between two breakpoints and k represents the breakpoint distance threshold.
Step 3.3: removing the false breakpoint:
before determining the initial search point of the edge, the false breakpoints existing in the breakpoints need to be removed, and the main method is to set the values at all the positions of the breakpoints to 0 and detect the breakpoints in the edge graph again. This will remove the false breakpoint and update the other location breakpoints to their neighboring edge points.
eMap[x i ,y i ]=0,(x i ,y i )∈BP[(x b1 ,y b1 ),(x b2 ,y b2 )…(x bn ,y bn )]
Where BP represents a set of breakpoints, eMap [ x ] i ,y i ]Representing a pixel (x) i ,y i ) The edge pixel value of (1);
step 3.4: update all breakpoints onto the super-split edge:
the main method is that whether the current breakpoint is on the super-segmentation edge or not is judged, if not, the position of the edge point adjacent to the breakpoint is judged in eight neighborhoods with the breakpoint as the center, then three pixel points symmetrical to the breakpoint are found, wherein the gradient maximum point is used as a new breakpoint until the breakpoint is updated to the super-segmentation edge.
Through the steps, the initial point position of the edge search can be obtained.
Further, the step 4 specifically includes the following steps:
step 4.1: search for fracture edges on the super-segmentation edges:
if assume the edge direction D [ x ] of the b-th breakpoint b ,y b ]=0 (horizontal direction), namely the initial search path is horizontal direction, first determine the edge pixel adjacent to the breakpoint is located at (x) b -1,y b -1),(x b -1,y b ),(x b -1,y b + 1), find out (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 super-segmentation edge pixels, selecting neighborhood pixel points with the maximum gradient amplitude, and if the pixel points do not belong to edge pixels, adding the pixel points into an edge pixel set and using the pixel points as new search starting points. If the edge pixel adjacent to the break point 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), repeating the above operations. If the edge direction of the current breakpoint is the vertical direction, first, it is determined that the edge pixel adjacent to the breakpoint is located at (x) b -1,y b -1),(x b ,y b -1),(x b +1,y b -1) finding (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 selecting the neighborhood pixel point with the maximum gradient amplitude as a new search point by the existing hyper-segmentation edge pixels. If the edge pixel adjacent to the break point is 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 repeating the above operations. The above operation is repeated. The search continues from the new search point until the number of breakpoints remains unchanged.
Step 4.2: and reversing the direction of the new breakpoint position:
and after all the breakpoints are searched, carrying out breakpoint detection on the generated edge graph again, and also carrying out edge search again by adopting direction inversion operation because the part of the breakpoints are restrained by the edge direction.
Step 4.3: and (5) repeating the step 4.1 and the step 4.2, stopping searching until the number of the broken points is equal to that of the broken points searched for at the last time, and finally obtaining a complete closed edge profile.
Due to the adoption of the technical scheme, the invention has the following beneficial effects:
1. the EDraking algorithm is used for extracting high-quality edge chains in the image, parallelization acceleration is carried out on the edge chains, the operation efficiency of the algorithm is improved, and meanwhile initial edge information of the image is provided.
2. A mark-based watershed algorithm is utilized to obtain a super-segmentation edge map containing weak edge information, a search path is provided for searching for a fracture edge, and the effectiveness of edge search is guaranteed.
3. Defining a breakpoint and proposing a search strategy, proposing fracture edge search from the breakpoint position, taking a super-segmentation edge image as a path image of the fracture edge, carrying out edge search by utilizing the characteristic of higher gradient of the edge part, obtaining a closed edge profile, and further obtaining an image segmentation effect.
Drawings
FIG. 1 is a flow chart of an algorithm according to the present invention;
FIG. 2 is a diagram illustrating the effect of initial edge detection;
FIG. 3 is a schematic diagram illustrating the effect of super-segmentation edges;
FIG. 4 is a schematic view of a full edge;
FIG. 5 is a CUDA acceleration flow diagram;
FIG. 6 is a schematic diagram of a breakpoint;
FIG. 7 is a schematic diagram of a breakpoint distance connection;
FIG. 8 is a schematic diagram of a pseudo breakpoint;
FIG. 9 is a schematic diagram of breakpoint updates on a super-split edge;
FIG. 10 is a schematic illustration of an edge search;
FIG. 11 is an original drawing of a building scene;
FIG. 12 is a schematic diagram of a building scene segmentation;
FIG. 13 is an indoor scene original drawing;
fig. 14 is a schematic diagram of indoor scene segmentation.
Detailed Description
The method of carrying out the invention is further illustrated with reference to the accompanying figures 1 to 14.
The embodiment provides an image segmentation algorithm based on watershed constraint and edge connection, a flow chart of which is shown in fig. 1, and the method comprises the following steps of firstly carrying out initial edge detection on an image to obtain preliminary edge information, then obtaining a super-segmentation edge path search graph by using a watershed algorithm, and finally carrying out fracture edge connection to obtain a closed edge contour, thereby obtaining an accurate segmentation result:
step 1, inputting an RGB image, and obtaining an initial edge image by using an EDraking algorithm.
Step 1.1: graying the input RGB image, adopting a weighted average method, and carrying out weighted average calculation on three channels according to different weights to calculate the gray value corresponding to each pixel. The gray value gray of each pixel can be obtained by the formula:
gray=R*0.299+G*0.587+B*0.114
where R, G, B represent the red, green and blue components in the RGB color space, respectively.
And traversing all the pixels to obtain a gray-scale map corresponding to the input RGB image.
Step 1.2: the grayscale map is subjected to filter smoothing processing using a gaussian kernel having a size of 5 × 5 and a standard deviation of δ = 1.
Figure BDA0003768473890000071
Gauss[x,y]=gray[x,y]*H[x,y]
Wherein, (x, y) represents pixel, gray [ x, y ] represents gray graph, H [ x, y ] represents Gaussian filter, gauss [ x, y ] represents filter graph.
Step 1.3: calculating a gradient magnitude map and an edge directional diagram of the filtered image:
respectively calculating the horizontal gradient and the vertical gradient G of each pixel by using a Sobel operator based on the image of Gaussian filtering y And a gradient magnitude G.
Figure BDA0003768473890000072
Figure BDA0003768473890000073
G[x,y]=|G x |+|G y |
Wherein, G x Is a horizontal gradient, G y In the case of vertical gradient, a pixel gradient magnitude map of the image can be obtained by traversing all pixels in the image.
At the same time, by comparing the horizontal gradient G of each pixel x And a vertical gradient G y . If G x |≤|G y If the pixel is a horizontal pixel, the edge direction of the pixel is considered as a horizontal direction. If G x |>|G y And if the pixel point is in the vertical direction, the direction of the pixel point is considered to be the vertical direction, and an edge directional diagram can be obtained by traversing all pixels in the image.
Figure BDA0003768473890000081
Wherein D [ x, y ] represents the edge pattern.
Step 1.4: acquiring an anchor point diagram according to the gradient amplitude diagram and the edge directional diagram:
and if the difference between the gradient amplitude of the current pixel and the gradient amplitudes of the adjacent upper and lower pixels is larger than or equal to the threshold value of the anchor point, the pixel is taken as the anchor point. If the pixel point is in the vertical direction, the left and right adjacent pixels are compared.
Figure BDA0003768473890000082
Wherein, aMap [ x, y ]]Representative of anchor point plot, th anchor Representing the anchor threshold.
The anchor point image may be acquired by traversing all pixels in the entire image.
Step 1.5: connecting anchor points, drawing an initial edge map eMap:
first initialize edges set of chains E = { E = { E } 1 ,e 2 ,...,e m =0, for arbitrary anchor points (x) i ,y i ) And searching 8 neighborhood pixels, and if the edge direction of the current anchor pixel is the horizontal direction, namely the initial search path is the horizontal direction, searching 6 neighborhoods on the left and right of the horizontal direction. First search (x) i -1,y i -1),(x i -1,y i ) And (x) i -1,y i + 1), then G [ x ] is judged i -1,y i -1]、G[x i -1,y i ]And G [ x ] i -1,y i +1]And if the pixel point is not in the edge pixel set, adding the pixel point into the edge pixel set, and taking the pixel point as a new search point to repeat the steps. If there is no point meeting the search condition, then (x) is searched i +1,y i -1),(x i +1,y i ) And (x) i +1,y i + 1), repeating the above steps. And if the edge direction of the current anchor point pixel is the vertical direction, namely the initial search path is the vertical direction, searching 6 vertical neighborhoods. First search (x) i -1,y i +1),(x i ,y i + 1) and (x) i +1,y i + 1), then G [ x ] is judged i -1,y i +1]、G[x i ,y i +1]And G [ x ] i +1,y i +1]And if the pixel point is not in the edge pixel set, adding the pixel point into the edge pixel set, and taking the pixel point as a new search point to repeat the steps. If there is no point meeting the search condition, then searching (x) i -1,y i -1),(x i ,y i -1) and (x) i +1,y i -1) repeating the above steps. Repeating the above steps for all anchor points can obtain a series of single-pixel edge chains E. I.e. an initial edge map is obtained.
Step 2: and acquiring a super-segmentation edge map. Calculating a mark point required by a watershed algorithm by using a gradient magnitude image obtained by a Sobel operator, taking an image after Gaussian filtering as an input image, obtaining a super-segmentation effect image by using the mark-based watershed algorithm, and converting the super-segmentation effect image into a single channel to obtain a super-segmentation edge image;
step 2.1: calculating the mark points required by the watershed algorithm:
by using the gradient map G (x, y), the local maximum point of the entire image is taken as a marker point. And (4) taking the pixel point (x, y) as the center, comparing the pixel gradient amplitude with the pixel gradient amplitudes of the eight neighborhoods of the pixel point, and if the gradient amplitude of the point is larger than the gradient amplitudes of other pixel points, taking the point as a mark point.
Figure BDA0003768473890000091
Wherein i- > p represents eight neighborhood pixel points p of pixel point i, (p =1,2, \ 8230; 8). Mark [ x, y ] represents a Mark map.
Step 2.2: acquiring a super-segmentation edge map:
and (3) converting the image subjected to Gaussian filtering into a three-channel image as an input image, obtaining a super-segmentation edge map by using the mark points obtained in the step (2.1) and a watershed algorithm, and converting the super-segmentation edge map into a single-channel map.
wMap[x,y]=cvtColor(Watershed(Gauss[x,y],Mark[x,y]),BGR2GRAY)
Where wMap [ x, y ] represents a super-segmentation edge map, cvtColor (f [ x, y ], BGR2 GRAY) represents converting the three-channel map f [ x, y ] into a single channel, and Watershed () represents Watershed processing.
And step 3: determining a search initiation point of the fracture edge. And (4) carrying out breakpoint detection on the initial edge graph obtained in the step (1). And if the distance between the breakpoints is smaller than the set threshold value, performing distance connection on the breakpoints. And then carrying out pseudo breakpoint removing operation and carrying out breakpoint detection again. And (3) obtaining a super-segmentation edge graph by utilizing the step 2, and updating the break points which are not positioned on the super-segmentation edge according to a local connection method. All break points are used as initial points for edge search.
Step 3.1: acquiring a breakpoint in the initial edge graph:
the existence of the break point indicates that the edge has a fracture phenomenon, and the break point is also a starting point of searching the fracture edge by the fracture edge. The main method for detecting the break point is that firstly, the edge pixel value is 255, the background is 0, then the initial edge graph is traversed, the number N of pixels adjacent to the edge in each pixel eight neighborhood is counted, and if N is less than or equal to 1, the pixel point is a break point.
Figure BDA0003768473890000101
Where N represents the number of pixels adjacent to the edge, eMap [ x [ ] i->p ,y i->p ]And p is the p-th neighborhood of the eight neighborhoods.
Step 3.2: connecting breakpoint distance:
and setting a distance threshold value for the obtained breakpoints, calculating the distance between every two breakpoints, and performing linear connection on the breakpoints meeting the requirement in the threshold value. The distance threshold is set to 4.
d=|x 1 -x 2 |+|y 1 -y 2 |
Figure BDA0003768473890000102
Where d represents the distance between two breakpoints and k represents the breakpoint distance threshold.
Step 3.3: removing the false breakpoint:
before determining the initial search point of the edge, the false breakpoints existing in the breakpoints need to be removed, and the main method is to set the values at all the positions of the breakpoints to 0 and detect the breakpoints in the edge graph again. This will remove the false breakpoint and update the other location breakpoints to their neighboring edge points.
eMap[x i ,y i ]=0,(x i ,y i )∈BP[(x b1 ,y b1 ),(x b2 ,y b2 )…(x bn ,y bn )]
Where BP represents a set of breakpoints. eMap [ x ] i ,y i ]Representing a pixel (x) i ,y i ) The edge pixel value of (1).
Step 3.4: update all breakpoints onto the super-split edge:
in order to search the initial search point along the super-segmentation edge, all breakpoint positions are required to be ensured to be on the super-segmentation edge, the main method is to firstly judge whether the current breakpoint is on the super-segmentation edge, if not, judge the position of the edge point adjacent to the breakpoint by taking the breakpoint as the eight neighborhoods of the center, then find the gradient maximum value point of three pixel points symmetrical to the maximum value point, update the gradient maximum value point to a new breakpoint until the breakpoint is updated on the super-segmentation edge.
If the current breakpoint is assumed to be (x) b ,y b ) The edge point adjacent thereto is (x) b ,y b -1), judging G [ x ] b -1,y b +1],G[x b ,y b +1],G[x b +1,y b +1]Updating the gradient maximum point to be a new breakpoint; if the edge point adjacent to the break point is (x) b ,y b + 1), then G [ x ] is judged b -1,y b -1],G[x b ,y b -1],G[x b +1,y b -1](ii) a If the edge point adjacent to the break point is (x) b -1,y b -1), then G [ x ] is judged b +1,y b ],G[x b ,y b +1],G[x b +1,y b +1](ii) a If the edge point adjacent to the break point is (x) b +1,y b + 1), then determine G [ x ] b -1,y b ],G[x b -1,y b -1],G[x b ,y b -1](ii) a The edge point adjacent to the break point is located at (x) b +1,y b ),(x b -1,y b ),(x b -1,y b +1),(x b +1,y b -1), the same. And repeating the steps until the breakpoint is updated to the super-segmentation edge.
Through the steps, the initial point position of the edge search can be obtained.
And 4, step 4: and searching for a fracture edge to obtain an edge closed contour. And (3) taking the breakpoint obtained in the step (3) as a search starting point, taking the super-segmentation edge graph obtained in the step (2) as a search path, searching by adopting a method with the maximum local gradient, and after all breakpoints are searched, carrying out iterative search to finally obtain a complete edge profile under a termination condition so as to obtain an edge segmentation effect.
With a breakpoint (x) i ,y i ) Taking the eight neighborhoods as local search windows as centers, and the method specifically comprises the following steps:
step 4.1: searching for a fracture edge:
if assume the edge direction D [ x ] of the b-th breakpoint b ,y b ]=0 (horizontal direction), namely the initial search path is horizontal direction, first determine the edge pixel adjacent to the breakpoint is located at (x) b -1,y b -1),(x b -1,y b ),(x b -1,y b + 1), find out (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 super-segmentation edge pixels, selecting neighborhood pixel points with the maximum gradient amplitude, if the pixel points do not belong to the edge pixels, adding the pixel points into the edge pixel set, and using the pixel points as new search starting points. If the edge pixel adjacent to the break point 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), repeating the above operations. If the edge direction of the current breakpoint is the vertical direction, firstly, the adjacent edge pixel of the breakpoint is determined to be located at (x) b -1,y b -1),(x b ,y b -1),(x b +1,y b -1) finding (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 selecting the neighborhood pixel point with the maximum gradient amplitude as a new search point by the existing hyper-segmentation edge pixels. If the edge pixel adjacent to the break point is 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 repeating the above operations. The above operation is repeated. The search continues from the new search point until the number of breakpoints remains unchanged.
Step 4.2: and after all the breakpoint searches are finished, performing breakpoint detection on the generated edge graph again, reversing the edge direction of each breakpoint position, and performing a new round of search again.
Step 4.3: and (5) repeating the step 4.1 and the step 4.2, and stopping searching until the number of the broken points is equal to that of the broken points searched for the last time, so as to finally obtain a complete closed edge profile.
According to the invention, the edge information in the image is extracted, and the fracture edge between the edges is found out, so that the edge closed contour is obtained, and the image segmentation effect is further obtained. The method is mainly applied to the fields of image recognition, medical image processing and industrial quality inspection. The schematic diagrams of the segmentation effect by applying the method of the present invention are shown in fig. 11 to 14.
The above-described embodiments are merely illustrative of the preferred embodiments of the present invention, and are not intended to limit the scope of the present invention, and various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the spirit of the present invention are intended to fall within the protection scope defined by the claims of the present invention.

Claims (7)

1. An image segmentation algorithm based on watershed constraint and edge connection is characterized by comprising the following steps:
step 1: acquiring an initial edge map; converting the RGB color image into a gray image, performing Gaussian filtering on the gray image, and obtaining an initial edge image by using an edge detection algorithm after parallel acceleration;
and 2, step: acquiring a super-segmentation edge map; calculating a mark point required by a watershed algorithm by using the gradient magnitude image, taking the image after Gaussian filtering as an input image, obtaining a super-segmentation effect image by using the mark-based watershed algorithm, and converting the super-segmentation effect image into a single channel to obtain a super-segmentation edge image;
and 3, step 3: determining a fracture edge search initial point; performing breakpoint detection on the initial edge graph obtained in the step 1, performing distance connection on the initial edge graph if the distance between the breakpoints is smaller than a set threshold, then performing pseudo breakpoint removing operation, and performing breakpoint detection again; utilizing the step 2 to obtain a super-segmentation edge graph, updating the break points which are not positioned on the super-segmentation edge according to a local connection method, and taking all the break points as initial points of edge search;
and 4, step 4: searching a fracture edge to obtain an edge closed contour; and 3, taking the breakpoint obtained in the step 3 as a starting point of searching, taking the super-segmentation edge graph obtained in the step 2 as a searching path, searching by adopting a method with the maximum local gradient, finishing searching the breakpoint, performing iterative searching, and finally obtaining a complete edge profile under a termination condition so as to obtain an edge segmentation effect.
2. The image segmentation algorithm based on watershed constraint and edge connection as claimed in claim 1, wherein the step 1 specifically comprises the following steps:
step 1.1: converting the RGB color image to a gray image:
step 1.2: the gray image is gaussian filtered:
step 1.3: calculating a gradient amplitude map and an edge directional diagram of the filtered image:
step 1.4: obtaining an anchor point diagram according to the gradient amplitude diagram and the edge directional diagram:
step 1.5: and connecting anchor points to obtain an initial edge map.
3. The image segmentation algorithm based on watershed constraint and edge connection as claimed in claim 1, wherein the step 2 specifically comprises the following steps:
step 2.1: obtaining the mark points required by the watershed algorithm:
by using a gradient map G [ x, y ]]Taking the local maximum point of the whole image as a mark point and taking a pixel point (x) i ,y i ) If the gradient amplitude of the point is larger than that of other pixel points, the point is used as a mark point;
Figure FDA0003768473880000021
wherein, i- > p represents eight neighborhood pixel points p of the pixel point i, (p =1,2, \8230; 8), mark [ x, y ] represents a marked graph;
step 2.2: acquiring a super-segmentation edge map:
firstly, converting the image subjected to Gaussian filtering into a three-channel image as an input image, obtaining a super-segmentation edge image by using a watershed algorithm by using the mark points obtained in the step 2.1, and converting the super-segmentation edge image into a single-channel image;
wMap[x,y]=cvtColor(Watershed(Gauss[x,y],Mark[x,y]),BGR2GRAY)
where wMap [ x, y ] represents a super-segmentation edge map, cvtColor (f [ x, y ], BGR2 GRAY) represents converting the three-channel map f [ x, y ] into a single channel, and Watershed () represents Watershed processing.
4. The image segmentation algorithm based on watershed constraint and edge connection as claimed in claim 1, wherein the step 3 specifically comprises the following steps:
step 3.1: breakpoint detection:
firstly, enabling the edge pixel value to be 255 and the background value to be 0, then traversing the initial edge image, counting the number N adjacent to the edge pixel in eight neighborhoods of a current pixel i, and if N is less than or equal to 1, then enabling the current pixel point to be a breakpoint;
Figure FDA0003768473880000022
where N represents the number of pixels adjacent to the edge, eMap [ x ] i->p ,y i->p ]The pixel value of the pixel point x is represented, and p is the pth neighborhood of the eight neighborhoods;
step 3.2: breakpoint distance connection:
setting a distance threshold value for the obtained breakpoints, calculating the distance between every two breakpoints, and performing linear connection when the breakpoints within the threshold value are met;
d=|x 1 -x 2 |+|y 1 -y 2 |
Figure FDA0003768473880000031
wherein d represents the distance between two breakpoints, and k represents the breakpoint distance threshold;
step 3.3: removing the false breakpoint:
before determining the initial search point of the edge, the false break points existing in the break points need to be removed, and the main method is to set the edge pixel values at all the break point positions to 0 and detect the break points in the edge graph again. Thus, the false breakpoints can be removed, and the breakpoints at other positions are updated to be the edge points adjacent to the breakpoint;
eMap[x i ,y i ]=0,(x i ,y i )∈BP[(x b1 ,y b1 ),(x b2 ,y b2 )…(x bn ,y bn )]
where BP represents a set of breakpoints, eMap [ x ] i ,y i ]Representing a pixel (x) i ,y i ) The edge pixel value of (1);
step 3.4: update all breakpoints onto the super-split edges:
firstly, judging whether the current breakpoint is on the super-segmentation edge, if not, judging the position of an edge point adjacent to the breakpoint in an eight-neighborhood region with the breakpoint as the center, then finding three pixel points symmetrical to the edge point relative to the breakpoint, wherein a gradient maximum value point is used as a new breakpoint until the breakpoint is updated on the super-segmentation edge.
5. The image segmentation algorithm based on watershed constraint and edge connection as claimed in claim 1, wherein the step 4 specifically comprises the following steps:
step 4.1: searching for a broken edge on the super-segmentation edge, and after all breakpoints are searched, carrying out breakpoint detection on the generated edge graph again, wherein a part of new breakpoints exist;
and 4.2: and (3) reversing the direction of the new breakpoint position:
because the part of the break points are restrained by the edge direction, the edge search is carried out again by adopting the direction negation operation;
step 4.3: and (5) repeating the step 4.1 and the step 4.2, stopping searching until the number of the broken points is not changed, and finally obtaining a complete edge closed contour, namely obtaining the image segmentation effect.
6. The image segmentation algorithm based on watershed constraint and edge connection as claimed in claim 4, wherein: the specific method for updating all breakpoints to the super-segmentation edges in the step 3 is as follows:
assume that the current breakpoint is (x) b ,y b ) And the edge point adjacent thereto is (x) b ,y b -1), judging G [ x ] b -1,y b +1],G[x b ,y b +1],G[x b +1,y b +1]Is detected by the gradient of (c),updating the breakpoint to a new breakpoint; if the edge point adjacent to the break point is (x) b ,y b + 1), then G [ x ] is judged b -1,y b -1],G[x b ,y b -1],G[x b +1,y b -1](ii) a If the edge point adjacent to the break point is (x) b -1,y b -1), then G [ x ] is judged b +1,y b ],G[x b ,y b +1],G[x b +1,y b +1](ii) a If the edge point adjacent to the break point is (x) b +1,y b + 1), then G [ x ] is judged b -1,y b ],G[x b -1,y b -1],G[x b ,y b -1](ii) a The edge point adjacent to the break point is located at (x) b +1,y b ),(x b -1,y b ),(x b -1,y b +1),(x b +1,y b -1) repeating the above steps until the breakpoint is updated on the super-segmentation edge.
7. An image segmentation algorithm based on watershed constraints and edge joining according to claim 5, characterized in that: step 4.1 the specific method for searching the fracture edge on the super-segmentation edge is as follows:
if assume the edge direction D [ x ] of the b-th breakpoint b ,y b ]=0, the horizontal direction, that is, the initial search path is the horizontal direction, first determine that the edge pixel adjacent to the breakpoint is located at (x) b -1,y b -1),(x b -1,y b ),(x b -1,y b + 1), find out (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) superdividing the edge pixel, selecting the neighborhood pixel point with the maximum gradient amplitude, if the pixel point does not belong to the edge pixel, adding the pixel point into the edge pixel set, and using the pixel point as a new search starting point; if the edge pixel adjacent to the break point 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), repeating the above operations; if the edge direction of the current breakpoint is the vertical direction, first, it is determined that the edge pixel adjacent to the breakpoint is located at (x) b -1,y b -1),(x b ,y b -1),(x b +1,y b -1) finding (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 ) Selecting a neighborhood pixel point with the maximum gradient amplitude as a new search point by using existing hyper-segmentation edge pixels; if the edge pixel adjacent to the break point is 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 repeating the above operations, and continuing to search from the new search point until the number of broken points is kept unchanged.
CN202210893472.9A 2022-07-27 2022-07-27 Image segmentation algorithm based on watershed constraint and edge connection Pending CN115330821A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210893472.9A CN115330821A (en) 2022-07-27 2022-07-27 Image segmentation algorithm based on watershed constraint and edge connection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210893472.9A CN115330821A (en) 2022-07-27 2022-07-27 Image segmentation algorithm based on watershed constraint and edge connection

Publications (1)

Publication Number Publication Date
CN115330821A true CN115330821A (en) 2022-11-11

Family

ID=83920435

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210893472.9A Pending CN115330821A (en) 2022-07-27 2022-07-27 Image segmentation algorithm based on watershed constraint and edge connection

Country Status (1)

Country Link
CN (1) CN115330821A (en)

Similar Documents

Publication Publication Date Title
CN108827316B (en) Mobile robot visual positioning method based on improved Apriltag
CN112837290B (en) Crack image automatic identification method based on seed filling algorithm
CN109993099A (en) A kind of lane line drawing recognition methods based on machine vision
CN107240112B (en) Individual X corner extraction method in complex scene
CN106815583B (en) Method for positioning license plate of vehicle at night based on combination of MSER and SWT
CN111611643A (en) Family type vectorization data obtaining method and device, electronic equipment and storage medium
CN109658391B (en) Circle radius measuring method based on contour merging and convex hull fitting
CN115082466B (en) PCB surface welding spot defect detection method and system
CN109598681B (en) No-reference quality evaluation method for image after repairing of symmetrical Thangka
CN104700420A (en) Ellipse detection method and system based on Hough conversion and ovum identification method
CN104318559A (en) Quick feature point detecting method for video image matching
CN103198319A (en) Method of extraction of corner of blurred image in mine shaft environment
CN105447489A (en) Character and background adhesion noise elimination method for image OCR system
CN105678737A (en) Digital image corner point detection method based on Radon transform
CN113780110A (en) Method and device for detecting weak and small targets in image sequence in real time
CN113435452A (en) Electrical equipment nameplate text detection method based on improved CTPN algorithm
CN110348307B (en) Path edge identification method and system for crane metal structure climbing robot
CN117094975A (en) Method and device for detecting surface defects of steel and electronic equipment
CN116542968A (en) Intelligent counting method for steel bars based on template matching
CN114419006A (en) Method and system for removing watermark of gray level video characters changing along with background
CN111091071A (en) Underground target detection method and system based on ground penetrating radar hyperbolic wave fitting
CN113610052A (en) Tunnel water leakage automatic identification method based on deep learning
CN108242060A (en) A kind of method for detecting image edge based on Sobel operators
Gooda et al. Automatic detection of road cracks using EfficientNet with residual U-net-based segmentation and YOLOv5-based detection
CN111429437B (en) Image non-reference definition quality detection method for target detection

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination