Watershed is a widely used image segmentation algorithm. A grayscale image is considered as topographic relief, which is flooded from initial basins. However, frequently they are not aware of the options of the algorithm and the peculiarities of its realizations. There are many watershed implementations in software packages and products. Even if these packages are based on the identical algorithm–watershed by flooding, their outcomes, processing speed, and consumed memory, vary greatly.
1. Introduction
Image segmentation by the watershed algorithm, because of its innate ability to produce closed-regions, has many applications in science, medicine, and industry. Despite the great advances of deep neural networks (DNN) intended for segmentation, watershed remains an important technique for solving some specific segmentation problems. One of the typical uses for watershed is separation of touching or overlapping objects in a binary image to employ an instance segmentation, when semantic segmentation has been previously performed by another technique. Currently, DNN and watershed are often used jointly
[1][2][3].
Typically, training courses and guides on computer vision or image processing only explain the general concept of a watershed. The name refers metaphorically to a geographical watershed, which separates adjacent drainage basins. A 2D image or some of its derivatives are treated as topographic relief (landscape). In classical watershed, local minima in the relief are initial basins. In a marker-controlled method, the markers are initial basins. Starting from the minimum of lowest height, the water gradually fills up all catchment basins. Image elements where water from different basins meets are called by watershed lines (WL) or dams. The process ends when the water reaches the maximum peak of the relief, and as a result, every catchment basin (i.e., segment) gets covered by WL. There is another explanation. Image elements at which a drop of water falls to the given local minimum form a catchment basin. Image elements at which a drop of water can fall to different basins form ridges or WL. Even if the watershed description was completed via a set theory of mathematical morphology (for example, see the well-known book by Gonzalez and Woods
[4]), it does not reflect the peculiarities of the algorithms and their implementations in software.
Figure 1 illustrates the simplest explanation of the watershed idea for an one-dimensional signal. Pixels of relief are in a gray. Initial markers are designated by the crosses in red, blue, and green. Filling starts from the initial markers, and as result, three segments (in red, blue, and green, respectively) are formed. Watershed lines (in black) are placed between the segments.
Figure 1. Illustration of marker-controlled watershed for one-dimensional signal.
2. Description of Watershed Algorithms Applied in Software
Because the considered algorithms are intended for processing both 2D and 3D images (strictly speaking, n-dimensional images can be processed), we use the term “image element” together with the terms pixel and voxel. Beucher and Lantuéjoul
[5] introduced watershed for segmentation of grayscale images, although the watershed transformation as an operation of mathematical morphology was described a few years earlier
[6][7]. To solve the oversegmentation problem caused by a huge number of initial basins started from each local minima of an image marker-controlled (or seeded) watershed was proposed
[8]. Vincent and Soille
[9] generalized watershed for an n-dimensional image and depicted an algorithm based on an immersion process analogy, in which the flooding of relief by water is simulated using a queue (first-in-first-out (FIFO) data structure) of image elements.
Beucher and Meyer
[10] developed effective algorithms, in which a flooding process is simulated by using a priority queue
[11], where a priority is a value of a relief element, and a lower value corresponds to a higher priority. An illustrative example of a pseudocode describing steps of marker-controlled watershed by Beucher and Meyer is reported in Algorithm 1. Here, we explain the variables and steps of this algorithm:
One can see that the algorithm by Beucher and Meyer does not form WL. Frequently, watershed lines are valuable segmentation outputs. Meyer [12] described the algorithm with WL construction. Pseudocode of this method is presented in Algorithm 2.
Paper [13] presents source codes of Algorithms 1 and 2 for processing 3D images with 26-connectivity in the Python programming language.
Let us consider how to operate the above described marked-controlled algorithms with WL [12] and without WL [10] construction. Figure 2a shows a binary image containing
two overlapping discs. We generated this image by a simple code in Python. Then, we create a relief by subtracting a constant from a rectangular area in the center part of the
inverted Euclidean distance transform (EDT) result for image containing two overlapping disks (see Figure 2b). The image containing initial markers (red and blue) is generated by placing the red and blue squares in the centers of the discs (Figure 2c); correspondingly, the markers are located in local minima of the relief. Segmentation results obtained by algorithms with (Figure 2e) and without WL (Figure 2d) construction are different. This example refutes the common misconception that differences in outcomes of watershed with and without WL result only from image elements of WL. The example clearly shows that segmentation results can vary.
Figure 2. (a) Two overlapping binary discs; (b) relief; (c) initial markers; (d) segmentation result without watershed lines (WL) construction; (e) segmentation result with WL construction.
Although all flooding-based implementations have estimation of computational complexity as O(N), where N is the number of image elements, its processing speed strongly
depends on the used data structures, applied programming language, software optimizations, asymptotic constant, and other parameters [14]. Hendriks [15] performed research
on various priority queues in terms of performance and demonstrated the importance of selecting the appropriate priority queue realization. For digital elevation models (DEM) used in geographic information systems (GIS), Barnes et al. [16] showed how the choice of different queues affects a performance of flooding-based watershed algorithms.
Over the 30-year history of the watershed, many algorithms have been developed: by topographic distance [17], via image foresting transform [18][19], rain falling [20][21],
toboggan-based [22], via minimum spanning forest [23][24], hierarchical watersheds [25], etc. Surveys [26][27][28] compare various approaches for a watershed calculation. However,
despite the enormous efforts to formulate the various mathematical concepts of watershed, only flooding-based algorithms are implemented in well-known software libraries.
Even if these packages are based on the identical algorithm, their outcomes, processing speed, and consumed memory, vary greatly. Papers [29][13] contain comprehensive benchmarking of various marker-controlled watershed implementations in software libraries and products.
This entry is adapted from the peer-reviewed paper 10.3390/jimaging8050127