# Synopse

Distance transform.

• y = iadist(f, Bc=ia_secross(), METRIC=NULL)
• y: Image
• f: Image
• Bc: Structuring Element (connectivity): secross() gives city-block, sebox() gives chessboard
• METRIC: String 'EUCLIDEAN', or 'EUC2' for squared Euclidean.
```01. from numpy import *
02. from string import upper
03. from iasecross import iasecross
04.
06.     from iagray import iagray
07.     from iaintersec import iaintersec
08.     from iaisequal import iaisequal
09.     from iaero import iaero
10.     from iasebox import iasebox
11.
12.     if METRIC is not None: METRIC = upper(METRIC)
13.     f = iagray(f,'uint16')
14.     y = iaintersec(f,0)
15.     if (METRIC == 'EUCLIDEAN') or (METRIC == 'EUC2'):
16.         f = int32(f)
17.         b = int32(zeros((3,3)))
18.         i=1
19.         while any(f != y):
20.             a4,a2 = -4*i+2, -2*i+1
21.             b = int32([[a4,a2,a4],
22.                        [a2, 0,a2],
23.                        [a4,a2,a4]])
24.             y=f
25.             i=i+1
26.             f = iaero(f,b)
27.         if METRIC == 'EUCLIDEAN':
28.             y = uint16(sqrt(f)+0.5)
29.     else:
30.         if iaisequal(Bc, iasecross()):
31.             b = int32([[-2147483647,  -1, -2147483647],
32.                        [         -1,   0,          -1],
33.                        [-2147483647,  -1, -2147483647]])
34.         elif iaisequal(Bc, iasebox()):
35.             b = int32([[-1,-1,-1],
36.                        [-1, 0,-1],
37.                        [-1,-1,-1]])
38.         else: b = Bc
39.         while any(f != y):
40.             y=f
41.             f = iaero(f,b)
42.     return y```

# Description

iadist creates the distance image y of the binary image f. The value of y at the pixel x is the distance of x to the complement of f, that is, the distance of x to nearest point in the complement of f. The distances available are based on the Euclidean metrics and on metrics generated by a a regular graph, that is characterized by a connectivity rule defined by the structuring element Bc: 4-connected gives city-block metric and 8-connected gives chessboard metric.

# Examples

## Example 1

```01. from ia870 import iadist
02. from ia870 import iaframe
03. from ia870 import iabinary
04. from ia870 import iasebox
05. from ia870 import ianeg
06.
07. a = iaframe( iabinary(ones((5,9))),WT=4,HT=2)
11. print 'a:\n', a
12. print 'f4:\n', f4
13. print 'f8:\n', f8
14. print 'fe:\n', fe```
```a:
[[ True  True  True  True  True  True  True  True  True]
[ True  True  True  True  True  True  True  True  True]
[ True  True  True  True False  True  True  True  True]
[ True  True  True  True  True  True  True  True  True]
[ True  True  True  True  True  True  True  True  True]]
f4:
[[6 5 4 3 2 3 4 5 6]
[5 4 3 2 1 2 3 4 5]
[4 3 2 1 0 1 2 3 4]
[5 4 3 2 1 2 3 4 5]
[6 5 4 3 2 3 4 5 6]]
f8:
[[4 3 2 2 2 2 2 3 4]
[4 3 2 1 1 1 2 3 4]
[4 3 2 1 0 1 2 3 4]
[4 3 2 1 1 1 2 3 4]
[4 3 2 2 2 2 2 3 4]]
fe:
[[4 4 3 2 2 2 3 4 4]
[4 3 2 1 1 1 2 3 4]
[4 3 2 1 0 1 2 3 4]
[4 3 2 1 1 1 2 3 4]
[4 4 3 2 2 2 3 4 4]]
```
```1. import ia636
2. a = ones((5,4),'bool')
4. print 'info(d):', ia636.iaimginfo(d)
5. print 'd=\n',d```
```info(d): <type 'numpy.ndarray'> (5, 4) uint16 256.000000 256.000000
d=
[[256 256 256 256]
[256 256 256 256]
[256 256 256 256]
[256 256 256 256]
[256 256 256 256]]
```

## Example 2

```01. from ia870 import ianeg
03. from ia636 import ianormalize
04.