Watershed transformation is a watershed image of the input image, and the boundary points between watersheds are watersheds. Obviously, the watershed represents the maximum point of the input image. Therefore, in order to obtain the edge information of an image, a gradient image is usually used as an input image, that is,
g(x,y)=grad(f(x,y))={[f(x,y)-f(x- 1,y)]2[f(x,y)-f(x,y- 1)]2}0.5
Where f(x, y) represents the original image, grad{ } stands for gradient operation.
Watershed algorithm has a good response to weak edges, and noise in the image and subtle gray changes on the surface of the object will produce excessive segmentation. But at the same time, it should be noted that the watershed algorithm has a good response to weak edges, which is guaranteed by closed continuous edges. In addition, the closed catchment basin obtained by watershed algorithm provides the possibility for analyzing the regional characteristics of the image.
In order to eliminate the over-segmentation caused by watershed algorithm, there are usually two processing methods. One is to use prior knowledge to remove irrelevant edge information. The second is to modify the gradient function so that the catchment basin only responds to the target to be measured.
In order to reduce the over-segmentation caused by watershed algorithm, gradient function usually needs to be modified. A simple method is to threshold the gradient image to eliminate the over-segmentation caused by the slight change of gray level. that is
g(x,y)=max(grad(f(x,y)),gθ)
Where gθ represents a threshold.
The program can adopt the following methods: using a threshold to limit the gradient image, eliminating excessive segmentation caused by small changes in gray values, and getting suitable areas, and then sorting the gray levels of the edge points of these areas from low to high, and then realizing the flooding process from low to high, and calculating the gradient image with Sobel operator. In the threshold segmentation of gradient image, the selection of appropriate threshold has great influence on the final segmentation image, so the selection of threshold is a key to the image segmentation effect. Disadvantages: the actual image may contain weak edges, and the numerical difference of gray level change is not particularly obvious. If the threshold is too large, these weak edges may be eliminated.