Elsevier

Pattern Recognition Letters

Volume 26, Issue 9, 1 July 2005, Pages 1266-1274
Pattern Recognition Letters

A fast watershed algorithm based on chain code and its application in image segmentation

https://doi.org/10.1016/j.patrec.2004.11.007Get rights and content

Abstract

In this paper, a novel algorithm is proposed for the watershed transformation. This new algorithm is based on chain code. The traditional concept of chain code is first expanded into point-out chain code and point-in chain code. Then two theorems, which depict how to make watershed transformation based on chain code, are proposed and proved. In the end, the description of this new algorithm is presented, and its complexity is discussed in detail. Experiments show that the presented algorithm runs fast. Further more, the new algorithm can provide more information to the following image processing.

Introduction

The traditional watershed transformation algorithm is usually implemented by simulating a flooding process (Hagyard et al., 1996, Vincent and Soille, 1991). During the processing, the image is taken as a surface of mountainous terrain, and the gray value of each pixel denotes the altitude of that point. In this terrain, there exist deep valleys (minima), high ridges (watershed lines), and steep or gentle hillsides (catchment basins). Firstly, holes are pierced in each minimum, and then this surface is slowly immersed into a lake. Starting from the minima of lowest altitude, water will progressively fill up the different catchment basins. Now, at the points where the water coming from different minima would merge, a ‘dam’ is built to prevent intermingle. At the end of the flooding procedure, each minimum is completely surrounded by dams, which delimit its associated catchment basins. All the dams correspond to the watersheds that are needed. Fig. 1 shows such one-dimension flooding process.

Vincent and Soille (1991) proposed the classical watershed algorithm (called Algorithm VS). This algorithm has two main steps: sorting and flooding. First, all pixels are sorted in the ascending order of their gray values. So the pixels of the same gray value can be directly accessed simultaneously. Once the pixels have been sorted, the progressive flooding can be processed from the minimal gray level. Suppose the flooding has been done up to a given level h, each catchment basin that is already discovered—i.e., those catchment basins whose corresponding minimum has the altitude lower or equal to h—is supposed to have a unique label. Then the pixels of altitude h + 1 will be processed. Those pixels among them, which have at least one labeled neighbor, are put into a first-in-first-out queue. Starting from these pixels, the queue structure enables to extend the labeled catchment basins including them by computing geodesic influence zones. Then those remained unlabeled pixels of level h + 1 are regarded as new minima, and given new labels. In the result, all the pixels belong to the same catchment basin have the same label, and those pixels have the same geodesic distance to different catchment basins are labeled as watershed pixels. Such watershed transformation is very close to the original concept of watershed, and can be easily comprehended. But its complexity is a little high because of the additional step of sorting. In addition, it cannot do image segmentation completely because the watershed pixels in broad watershed zones do not belong to any segmented regions.

Bieniek and Moga (2000) proposed a distinct watershed algorithm based on connected components (called Algorithm BM). This algorithm is implemented by simulating a raining process, not flooding as usual. When a raindrop drops on the image surface, it must flow along hillside down to the according valley. The route which raindrop passes is just a connected component, and is also a steepest path between fall-point and the valley. All the connected components, which lead to the same valley, form a catchment basin associated to it. This algorithm can label all catchment basins by only scanning the whole image four times. Compared with these methods implemented by simulating flooding, this algorithm is faster, and can segment image completely.

This paper presents a new watershed algorithm based on chain code. The novelty of this approach is to adopt chain code to depict connected components. The new algorithm first simulates raining to generate connected components using chain code instead of pixel address used in Algorithm BM, and then simulates flooding to label catchment basins by tracing chain codes. It also only scans image four times, and can segment image completely. Compared with Algorithm BM, the proposed algorithm can describe connected components more clearly, and provides more information to the following processing.

The paper is organized as follows: In Section 2, the traditional definition of chain code is expanded into point-out chain code and point-in chain code. Then two theorems, which depict how to make watershed transformation based on chain code, are proposed and proved. In Section 3, the description of the new algorithm is presented, and then its complexity is discussed in detail. Experiments and conclusions are shown in Section 4.

Section snippets

Definitions and theorems for chain code based watershed transformation

Chain code is a very common tool in image processing. This paper first expands the traditional concept of chain code into point-out chain code and point-in chain code.

Definition 1

Point-out chain code is the directional code that current pixel points to one of the eight neighbor pixels, shown in Fig. 2(a).

The value of point-out chain code can be any one in the set {0, 1, 2, 3, 4, 5, 6, 7, and 8}, where the code ‘8’ means current pixel does not point to any neighbor pixel. This paper restricts each pixel can

Algorithm description

According to above discussion, chain code based watershed algorithm is described as below:

  • Input:  source image f

  • Output: label image l

  • Step 0: Initialize

    •  PointOut(·): Point-out chain code, initialized to 8;

    •  PointIn(·): Point-in chain code, initialized to 0.

  • Step 1: Label point-out and point-in chain codes of the pixels having lower neighbors

    •  p: Current pixel

    •  p  N(p): Neighbor pixel of p

    •  f(p), f(p′): The gray value of p, p

    •  q={pN(p)f(p)=minpN(p)f(p),f(p)<f(p)}: The steepest neighbor

    •  PO_Code(p  q):

Experiments and conclusion

As is known, the image segmentation based on watershed follows such basic steps, shown in Fig. 4. In the procedure, the preprocessing of gradient calculation is essential. Only in the gradient image, the boundaries of objects could be located on the ridges and taken as watershed pixels, and then the watershed algorithm could work in the right way. At the same time, the step of noise reduction and the method of calculating gradient also affect the initial region numbers of watershed

References (5)

There are more references available in the full text version of this article.

Cited by (69)

  • Flow distance induced variation analysis of digitally segmented steel fibers in UHPFRC

    2021, Construction and Building Materials
    Citation Excerpt :

    The next step is the actual watershed algorithm, that will use the distance map as an input parameter to separate the binary input dataset. There are many different algorithms to perform this watershed separation, but a fast algorithm based on chain code developed by Sun et al., [47] was implemented in this study. Subsequently, the separated individual fibers were labeled for identification (Fig. 3(e)), and the information for each fiber (e.g., volumes of fibers and coordinates of the centroid and orientation) was calculated.

  • Boolean operations on rasterized shapes represented by chain codes using space filling curves

    2017, Journal of Visual Communication and Image Representation
View all citing articles on Scopus
View full text