Function iatz - Tie-Zone watershed transform

Synopse

Tie-Zone transform by max-path cost function with lexicographic cost.

  • y = iatz(f, Bc=iasecross())
    • y: Image
    • f: Image
    • Bc: Structuring Element (connectivity)
01. from ia870 import iasecross
02. 
03. # constants
04. MASK = -2
05. TIE_ZONE = 0
06. 
07. def iatz(f, Bc=iasecross()):
08.     from ipdp import se2offset
09. 
10.     offset = se2offset(Bc)
11.     return tieZone(f, offset)
12. 
13. 
14. 
15. def tieZone(im, offsets):
16. 
17.     import numpy as np
18.     from ipdp import wsImage
19.     from ipdp import findMinima
20.     from ipdp import wsHeapQueue
21. 
22.     # initialise variables
23.     ws = wsImage(im)
24.     N, im, lab, D = ws.begin(offsets)
25. 
26.     # find minima
27.     M = findMinima(im, N, D)
28. 
29.     # create the working images
30.     done = ws.makeWorkCopy(False)
31.     c1 = ws.makeWorkCopy(np.inf)
32.     c2 = ws.makeWorkCopy(0)
33.     par = ws.makeWorkCopy(MASK)
34.     lab[:] = MASK
35. 
36.     queue = wsHeapQueue()
37. 
38.     for m in xrange(len(M)):
39.         for p in M[m]:
40.             c1[p] = im[p]
41.             lab[p] = m+1
42.             par[p] = p
43.             queue.push(p, im[p])
44. 
45.     while not queue.empty():
46.         p = queue.pop()
47.         done[p] = True
48.         for q in N(p):
49.             if done[q]:
50.                 continue
51. 
52.             c = max(c1[p], im[q])
53.             if c < c1[q]:
54.                 if c1[q] < np.inf:
55.                     if queue.contains(q, c1[q]):
56.                         queue.remove(q, c1[q])
57.                 c1[q] = c
58.                 lab[q] = lab[p]
59.                 par[q] = p
60.                 queue.push(q, c1[q])
61.                 if c == c1[p]:
62.                     c2[q] = c2[p] + 1
63.             elif c == c1[q] and lab[q] != lab[p]:
64.                 if c == c1[p]:
65.                     if c2[q] == c2[p] + 1:
66.                         lab[q] = TIE_ZONE
67.                 else:
68.                     lab[q] = TIE_ZONE
69. 
70.     return ws.end()

Description

iatz segments the image f on the image of labels y. The labels of y form connected components which belong to all possible solutions of the watershed transform using a max-path cost function. Pixels that do not belong to any of these regions form the tie-zone, receiving a value 0, interpreted as a label TZ. The neighbourhood for the algorithm is defined by structuring element Bc. The implementation of this code is based on algorithm of Audigier, Lotufo and Couprie [1].

Examples

Example 1

1. from ia870 import *
2. 
3. f = adreadgray('astablet.tif')
4. grad = iagradm(f)
5. w = iatz(grad, iasebox())
6. adshow(grad)
7. adshow(iaglblshow(w))

Example 1

1. gf = iaareaclose(grad,1000)
2. wt = iatz(gf, iasebox())
3. adshow(gf, 'filtered gradient')
4. adshow(iaglblshow(wt),'tiezone watershed')

filtered gradient

tiezone watershed

Equation

is the set containing all possible solutions:

Limitations

The structuring elements must be symmetric.

References

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