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)
``` 1 from ia870 import iasecross
2
3 # constants
5 TIE_ZONE = 0
6
7 def iatz(f, Bc=iasecross()):
8     from ipdp import se2offset
9
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)
34
35     queue = wsHeapQueue()
36
37     for m in xrange(len(M)):
38         for p in M[m]:
39             c1[p] = im[p]
40             lab[p] = m+1
41             queue.push(p, im[p])
42
43     while not queue.empty():
44         p = queue.pop()
45         done[p] = True
46         for q in N(p):
47             if done[q]:
48                 continue
49
50             c = max(c1[p], im[q])
51             if c < c1[q]:
52                 if c1[q] < np.inf:
53                     if queue.contains(q, c1[q]):
54                         queue.remove(q, c1[q])
55                 c1[q] = c
56                 lab[q] = lab[p]
57                 queue.push(q, c1[q])
58                 if c == c1[p]:
59                     c2[q] = c2[p] + 1
60             elif c == c1[q] and lab[q] != lab[p]:
61                 if c == c1[p]:
62                     if c2[q] == c2[p] + 1:
63                         lab[q] = TIE_ZONE
64                 else:
65                     lab[q] = TIE_ZONE
66
67     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

Numerical examples

```1 import numpy as np
2 import ia870 as MT
3
4 f = np.array([[ 0, 5, 10, 4, 0],
5               [11, 5,  4, 3, 1]],'uint8')
6 w = MT.iatz(f, MT.iasecross())
7 print 'f=\n',f
8 print 'w=\n',w
```
```f=
[[ 0  5 10  4  0]
[11  5  4  3  1]]
w=
[[1 1 0 2 2]
[0 2 2 2 2]]
```
```1 f = np.array([[ 0, 4, 10, 4, 0],
2               [11, 5,  4, 3, 1]],'uint8')
3 w = MT.iatz(f, MT.iasecross())
4 print 'f=\n',f
5 print 'w=\n',w
```
```f=
[[ 0  4 10  4  0]
[11  5  4  3  1]]
w=
[[1 1 0 2 2]
[0 0 2 2 2]]
```

Example 1

```1 from ia870 import *
2
```

Example 1

```1 gf = iaareaclose(grad,1000)
2 wt = iatz(gf, iasebox())