# Synopsis

Prototype:
y = connectedComponents(f, offsets)
Description:
The connectedComponents function implements the watershed transform using the algorithm of connected components by Bieniek and Moga [BieniekMogaPR2000]. This algorithm computes the shortest paths using a drop of water simulation. It does not produce watershed pixels.
Definition:
LC-WT
Exploration:
Depth-First

# Algorithm

Algoritmo 1: Connected Components

# References

 [BieniekMogaISMM1998] A. Bieniek and A. Moga, ``A connected component approach to the watershed segmentation,'' in ISMM '98: Proceedings of the fourth international symposium on Mathematical morphology and its applications to image and signal processing. Norwell, MA, USA: Kluwer Academic Publishers, 1998, pp. 215–222.
 [BieniekMogaPR2000] A. Bieniek and A. Moga, ``An efficient watershed algorithm based on connected components,'' Pattern Recognition, vol. 33, no. 6, pp. 907–916, 2000.

# Source Code

``` 1 from ipdp.common import *
2
3 # constants
5 PLATEAU = -1
6
7 def connectedComponents(im, offsets):
8
9     # initialise variables
10     ws = wsImage(im)
11     N, im, lab, D = ws.begin(offsets)
12
15
16     queue = wsQueue()
17
18     def find(p):
19         q = p
22         u = p
26             u = v
27         return q
28
29     # step 1
30     for p in D:
31
32         q = p
33         for u in N(p):
34
35             if im[u] < im[q]:
36                 q = u
37
38         if q != p:
40         else:
42
43     # step 2
44     for p in D:
46             continue
47
48         for q in N(p):
49             if adr[q] == PLATEAU or im[q] != im[p]:
50                 continue
51
52             queue.push(q)
53
54     while not queue.empty():
55         p = queue.pop()
56         for q in N(p):
57             if adr[q] != PLATEAU or im[q] != im[p]:
58                 continue
59
61             queue.push(q)
62
63     # step 3
64     for p in D:
66             continue
67
69
70         for q in N(p):
71             if q > p or im[q] != im[p]:
72                 continue
73
74             u = find(p)
75             v = find(q)
77
78     # step 4
79     basins = 1
80     for p in D:
81
82         r = find(p)