tieZone

Synopsis

Prototype:
y = tieZone(f, offsets)
Description:
The tieZone function implements the tie-zone watershed transform calculating the shortest-path forests and unifying solutions on TZ pixels. These pixels receive a label with value zero. This algorithm was proposed by Audigier, Lotufo and Couprie. [AudigierLotufoCouprieICIP2005]
Definition:
TZ-IFT-WT
Exploration:
Breadth-First

Algorithm

Algoritmo 1: Tie-Zone Transform of IFT Watershed

References

[AudigierLotufoCouprieICIP2005]R. Audigier, R. de A. Lotufo, and M. Couprie, ``The tie-zone watershed: Definition, algorithm and applications,'' in Proceedings of IEEE International Conference on Image Processing (ICIP’05), vol. 2, pp. 654–657, 2005.

Source Code

 1 from ipdp.common import *
 2 
 3 # constants
 4 MASK = -2
 5 TIE_ZONE = 0
 6 
 7 def tieZone(im, offsets):
 8 
 9     # initialise variables
10     ws = wsImage(im)
11     N, im, lab, D = ws.begin(offsets)
12 
13     # find minima
14     M = findMinima(im, N, D)
15 
16     # create the working images
17     done = ws.makeWorkCopy(False)
18     c1 = ws.makeWorkCopy(inf)
19     c2 = ws.makeWorkCopy(0)
20     par = ws.makeWorkCopy(MASK)
21     lab[:] = MASK
22 
23     queue = wsHeapQueue()
24 
25     for m in xrange(len(M)):
26         for p in M[m]:
27             c1[p] = im[p]
28             lab[p] = m+1
29             par[p] = p
30             queue.push(p, im[p])
31 
32     while not queue.empty():
33         p = queue.pop()
34         done[p] = True
35         for q in N(p):
36             if done[q]:
37                 continue
38 
39             c = max(c1[p], im[q])
40             if c < c1[q]:
41                 if c1[q] < inf:
42                     if queue.contains(q, c1[q]):
43                         queue.remove(q, c1[q])
44                 c1[q] = c
45                 lab[q] = lab[p]
46                 par[q] = p
47                 queue.push(q, c1[q])
48                 if c == c1[p]:
49                     c2[q] = c2[p] + 1
50             elif c == c1[q] and lab[q] != lab[p]:
51                 if c == c1[p]:
52                     if c2[q] == c2[p] + 1:
53                         lab[q] = TIE_ZONE
54                 else:
55                     lab[q] = TIE_ZONE
56 
57     return ws.end()