Watershed image segmentation processing method
Technical Field
The invention relates to an image segmentation processing method, in particular to a morphological watershed image segmentation processing method.
Background
Image Segmentation watershed methods were originally introduced into the field of Image processing by Digabel and Lantujoul for analyzing simple binary images, meyer proposed in 1990 the most primitive Morphological watershed Segmentation method (Meyer F, beer s. Morphological Segmentation [ J ]. Journal of Visual Communication and Image Representation,1990,1 (1): 21-46.), but this method was extremely computationally complex and very difficult to implement, and vintage and soill proposed in 1991 the fast Morphological watershed methods (Luc view, pierce soill, watercut in Digital Spaces: organic affected Algorithm, segmentation algorithms, IEEE Transactions analysis, junction, and volume, for establishing a large number of images on water, volume, PAGE, and No. 5913. For analyzing simple binary images, and was used in the watershed theory of images, no. 1991. The watershed change basically overcomes the defects of a threshold segmentation method and an edge detection method, and the segmentation is fine, so that the method is a brand-new image segmentation method. In recent years, researches on a watershed method for image segmentation are continued, but because the computational complexity of the watershed method is relatively high, no method can be applied to occasions of real-time high-speed image segmentation. Among the many existing watershed methods, the immersion simulation-based method proposed by Vincent and solille is the most well-known and fastest method. The method comprises two parts: the first part is sorting; the second part is flooding. The method can be briefly described as follows (wherein step 1 is a sequence, step 2 to step 6 are flooding):
step 1: firstly, calculating the gradient of each point in the image, and then scanning the whole image to obtain the histogram of the gradient image and the probability density of each gradient layer. The position of each pixel point in the sequencing array is calculated by the cumulative probability of the gradient distribution and the gradient value of the pixel point. And calculating the sequencing positions of all the pixel points and storing the sequencing positions into a sequencing array. In the sorted array, the lower the gradient value, the higher the position at which the lower the gradient value is stored.
Step 2: the pixel points are processed in order of gradient values from low to high, with points of the same gradient value as a gradient level.
And step 3: processing a gradient level h cur (current layer), first add all identified points of the neighborhood in the layer to a first-in-first-out queue.
And 4, step 4: if the FIFO queue is not empty. The first element of the pop-up queue is taken as the currently processed pixel. Sequentially processing the currentAll heights of pixels are h cur Of the adjacent point. And if the adjacent point is identified, refreshing the identification of the current pixel point according to the adjacent point identification. If the neighbor is not identified, the neighbor is added into the first-in first-out queue to circularly execute the step until the queue is empty.
And 5: and scanning the pixel points of the current gradient level again. It is checked whether there are still unidentified points. The unidentified point at this time means a new atomic region. Thus. And if the unidentified point is found, adding 1 to the current area identification value, and assigning the value as the identification value of the unidentified point. Then, the same flooding step as step 4 is performed from this point. All pixel points of the minimum region are identified.
Step 6: and returning to the step 3 to process the next gradient level. Until all gradient levels are processed.
In the conventional watershed image segmentation method, each pixel point is scanned for multiple times on average, for example, the sequencing process of the method proposed by Vincent-Soille is twice, and the flooding process is three times and five times in total, so that the execution time is linear.
For some methods with high real-time requirements (real-time video segmentation), the computational overhead is still too large. Therefore, a fast and effective watershed method becomes a technical problem for image study.
Disclosure of Invention
The invention aims to provide a quick and effective watershed image processing method, which is completed in three steps, namely a watershed method pre-processing process, a watershed process and a watershed post-processing process, and the flow of the method is shown in figure 1.
A watershed image segmentation processing method comprises the following steps:
1) Filtering the original image through a low-pass filter;
2) Smoothing each pixel point of the image to obtain a smooth image;
3) Respectively solving the horizontal gradient and the vertical gradient of each pixel point of the image, taking the larger gradient as the gradient of the point, and extracting the boundary of the image to obtain a gradient image;
4) Traversing each pixel point to obtain a histogram of the gradient image and the probability density of each gradient layer, traversing each pixel point again to obtain the position of each pixel point in the sequencing array, and sequencing the pixel points;
5) Labeling the gradient image, wherein the method comprises the following steps of judging whether four adjacent points of the upper, lower, left and right of the current processing point are labeled: if the marked points exist in the four adjacent points of the current processing point, the mark number of the current processing point is equal to the mark number; if the marked points do not exist in the four adjacent points of the current processing point, the current processing point is the new mark;
6) Sequentially scanning each pixel point of each gradient layer, and directly judging the label of each point in the scanning process; the method for determining the label of each point comprises the following steps: judging according to the types of the labels of the upper, lower, left and right neighboring points of the current processing point, wherein if the upper, lower, left and right neighboring points of the current processing point only have one label, the label of the current processing point is equal to the label; if the upper, lower, left, right and four adjacent points of the current processing point have two or more labels, the current processing point is positioned at the junction of two or more areas, and the current processing point is a watershed point; if the four adjacent points of the current processing point, namely the upper, lower, left and right adjacent points are not marked, the current processing point is a new mark;
7) The points with the same labels are marked as a region, and different regions are segmented by watershed lines, thereby realizing image segmentation.
The sorting array is a one-dimensional sorting array of the whole image from small to large according to gradient values, points with small gradients are arranged in front of points with large gradients, and points on the upper left are arranged in front of points on the lower right.
The method sets a threshold value for the gradient value, and the marks of the points with the gradient values smaller than the threshold value are set to be zero.
The method is characterized in that a threshold value is set for the number of points in a marked region in region division, and if the number of points in the marked region is smaller than the set threshold value, the region is merged into a left adjacent region.
The method for sequencing the pixel points in the method is an immersion simulation method.
In the method, a Gaussian template is adopted to carry out smoothing treatment on each pixel point of the image.
The Gaussian template is as follows:
in the method, a Sobel operator is adopted to calculate the horizontal gradient and the vertical gradient of each pixel point of the image.
The Sobel operator is:
wherein H 1 For horizontal gradient, H 2 Is a vertical gradient.
The invention has the advantages of
The invention can complete the image segmentation process more quickly while basically ensuring the image segmentation effect. FIG. 2 is a diagram showing the effect of the image segmentation method proposed herein and the image segmentation method proposed by Vincent-Soille. Table 1 lists the processing speed comparisons of the image segmentation method proposed herein and the Vincent-Soille proposed method.
Table 1 comparison of processing speed of the method herein with that of Vincent
Image(s)
|
Width of image
|
Height of image
|
Vincent time of use
|
Overall time of the algorithm
|
clair
|
128
|
128
|
32
|
16
|
lena
|
512
|
512
|
469
|
171
|
Testing the computer for use: AMD1.6G512M
|
Width and height unit: pixel, time unit: millisecond (ms)
|
Drawings
FIG. 1 is a system flow diagram of the present invention;
FIG. 2 is a plot of watershed line effects for the method presented herein and the VINCENT-SOLLE method;
FIG. 3 is a diagram of the effect of reducing the transition segmentation by using a threshold method, wherein a gradient threshold 2, a threshold 10, a threshold 15 and a threshold 22 are adopted from top to bottom; the left graph shows the segmentation effect of the method proposed herein, and the right graph shows the segmentation effect of the method proposed by VINCENT-SOLLE;
fig. 4 shows the effect graph of region fusion after using the threshold method, and sequentially adopts region fusion thresholds 10, 50, 100, and 120 from top to bottom, where the left graph shows the segmentation effect of the method proposed herein, and the right graph shows the segmentation effect of the method proposed herein.
Detailed Description
The image segmentation method can be used in image segmentation occasions with higher real-time requirement, such as the extraction process of video object VOB of MPEG-4, and the invention will be further explained by combining the drawings and the embodiment as follows:
preprocessing image segmentation by a watershed method:
the original image may carry noise points unrelated to the original image during data acquisition and storage. These noise points greatly affect the processing effect of the watershed method, thereby causing an over-segmentation phenomenon. Therefore, the original gray image must first be passed through a low-pass filter to filter out unnecessary noise points.
In order to better divide the region of the image by the watershed method, the region edge of the image needs to be emphasized, and the purpose can be realized by differential operator edge detection.
During the smoothing of the image, each pixel is processed using a gaussian template (1) (lufeng military, digital image processing programming entry, qinghua university press, 1999, published in 12 months, P43-P46).
In the process of extracting the boundary of the image, the Sobel operator (2) is used to respectively obtain the horizontal gradient and the vertical gradient of each pixel point of the image, and the larger gradient is taken as the gradient of the point (Lufeng military, digital image processing Programming entry, qinghua university Press, published in 12 months 1999, P118-P121).
H 1 For horizontal gradient, H 2 Is a vertical gradient
The image segmentation processing process of the watershed method comprises the following steps:
after the preprocessing, the watershed image segmentation can be carried out on the image. The watershed image segmentation method provided by the invention utilizes the position relation among all pixel points in a sequencing array in the flooding process, and labels of each gradient layer are sequentially expanded column by column and row by row from top left to bottom right. The image segmentation processing method can be divided into three steps of sorting, seed generation and flooding:
step 1, sequencing: the image processing method in the sorting module adopts the same mode as the VINCENT-SOLLE, namely, the histogram of the gradient image and the probability density of each gradient layer are obtained through the first traversal, and the position of each pixel point in the sorting array is obtained through the second traversal. Specifically, the probability density of the gradient indicates the number of pixel points having a gradient value smaller than the gradient. Therefore, after the probability density is obtained, the whole gradient image is traversed again, if the gradient value of a certain point is n, the probability density with the gradient being n is taken as the address of the point in the sequencing array, and the probability density with the gradient n is added with 1 to be taken as the address of the point with the gradient being n in the sequencing array next time. After two times of traversal, a one-dimensional sequencing array of the whole image from small to large according to the gradient value can be obtained. In this array, the dots with small gradients are arranged in front of the dots with large gradients, and the upper left dots are arranged in front of the lower right dots.
Step 2, seed generation: the seed generation module is to obtain the initial label (seed) of the gradient image, and the label of the lowest gradient layer is expanded here. That is, the pixels in the minimum gradient layer in the sorting array are sequentially taken out, and then the same or different labels are determined according to whether the points in the minimum gradient layer are adjacent (the label is different from the label in concept, and the label comprises a label and a watershed). The processing method comprises the following steps: judging whether four adjacent points of the current processing point, namely the upper, the lower, the left and the right, are labeled:
if the marked points exist in the four adjacent points of the current processing point, the mark number of the current processing point is equal to the mark number;
and if the marked points do not exist in the four adjacent points of the current processing point, the current processing point is the new mark.
Step 3, flooding: in view of the relevance of image gradients, i.e. points in an image with the same gradient will not usually appear isolated, all in the form of small regions of aggregation; in the sorting process, the sorting of the pixels of a certain gradient layer is considered to be arranged in a sorting array from top left to bottom right. Therefore, the flooding module of the document adopts a flooding method based on a sequencing sequence, the method scans all pixel points (from top to bottom and from left to right) of each gradient layer in sequence, and directly judges the label of each point in the scanning process. The determined method is that the flooding module judges according to the types of the marks of the upper, lower, left and right neighbors of the current processing point:
if the four adjacent points of the current processing point, namely the upper, the lower, the left and the right, have only one label, the label of the current processing point is equal to the label;
if the upper, lower, left and right adjacent points of the current processing point have two or more labels, the current processing point is positioned at the junction of two or more areas, and the current processing point is a watershed point;
and if the four adjacent points of the current processing point, namely the upper, lower, left and right adjacent points are not marked, the current processing point is a new mark.
After the original input image is subjected to Gaussian template smoothing processing, each frame of smoothed image is subjected to sequencing, seed generation and flooding steps, each pixel point of one image is labeled, the points with the same labels form a region, and different regions are segmented by watershed lines, so that image segmentation is realized. If the segmentation block is too small, a post-processing step of image segmentation by a watershed method can be selected to achieve the purpose of merging small regions and obtain a better image segmentation effect.
Post-processing of image segmentation by watershed method:
watershed methods all create a certain problem of transitional segmentation, and two steps are used to reduce the influence of the transitional segmentation. Wherein, the first step can be independently used, and when the requirement of segmentation is more definite, the second step can be added.
The method comprises the following steps: since the gradient represents the changing relationship between the pixels. Here, an approximation method is used to approximate a point where the change in gray level between two pixels is small, that is, a point where the gradient value is small, as no change between pixels, and consider the gradient thereof as zero. Thus, after the gradient is found, the gradient is thresholded, i.e., points where the gradient is less than a threshold are considered as points where the gradient is zero. Since the seed generation process will label the layer with the lowest gradient, these labels will become reference points in the later flooding process. Better segmentation effect can be generated by reasonably setting the threshold value. FIG. 3 is a diagram illustrating the effect of reducing the transition segmentation by using a threshold method, wherein a gradient threshold 2, a threshold 10, a threshold 15 and a threshold 22 are adopted from top to bottom; the left graph shows the segmentation effect of the proposed method, and the right graph shows the segmentation effect of the proposed method, VINCENT-SOLLE.
Table 2 lists the number of regions for the two methods when different thresholds are taken.
TABLE 2 number of regions processed by Clair with different thresholds
Number of corresponding regions of Clair image with different gradient thresholds
|
Threshold value
|
Number of regions of text algorithm
|
Vincent algorithm area number
|
2
|
1197
|
522
|
10
|
626
|
308
|
15
|
124
|
77
|
22
|
76
|
42
|
Step two: and performing region fusion on the marked regions, namely counting the number of points in each region. If the value is less than the threshold value set in advance, the region is merged into the adjacent region on the left side. And selecting an image with a gradient threshold value of 22 for the Claire image and then processing the image. Fig. 4 is a diagram of the effect of using the threshold method and then using the region fusion, sequentially adopting the region fusion thresholds 10, 50, 100, and 120 from top to bottom, the left diagram being the segmentation effect of the method proposed herein, and the right diagram being the segmentation effect of the method proposed by VINCENT-solid.
Table 3 shows the number of regions of the Claire image after region fusion.
TABLE 3 FIG. Clair uses thresholding and minimum post-cell fusion zone count
Taking the number of corresponding areas of different fusion thresholds from Claire image
|
Threshold value
|
Number of regions of algorithm
|
Vincent algorithm area number
|
10
|
34
|
19
|
50
|
12
|
25
|
100
|
11
|
22
|
120
|
9
|
20。
|