# Function iadil

namespace: morph iadil

# Synopse

Dilate an image by a structuring element.

• y = iadil(f, b=ia_secross(NULL))
• y: Image
• f: Image
• b: Structuring Element
```01. from numpy import *
02.
03. def iadil(f, b=None):
04.     from iamat2set import iamat2set
05.     from ialimits import ialimits
06.     from iaisbinary import iaisbinary
07.     from iaintersec import iaintersec
08.     from iagray import iagray
09.     from iaadd4dil import iaadd4dil
10.     from iasecross import iasecross
11.
12.     if b is None: b = iasecross()
13.
14.     if len(f.shape) == 1: f = f[newaxis,:]
15.     h,w = f.shape
16.     x,v = iamat2set(b)
17.     if len(x)==0:
18.         y = (ones((h,w)) * ialimits(f)[0]).astype(f.dtype)
19.     else:
20.         if iaisbinary(v):
21.             v = iaintersec( iagray(v,'int32'),0)
22.         mh,mw = max(abs(x)[:,0]),max(abs(x)[:,1])
23.         y = (ones((h+2*mh,w+2*mw)) * ialimits(f)[0]).astype(f.dtype)
24.         for i in range(x.shape[0]):
25.             if v[i] > -2147483647:
26.                 y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w] = maximum(
27.                     y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w], iaadd4dil(f,v[i]))
28.         y = y[mh:mh+h, mw:mw+w]
29.
30.     return y```

# Description

iadil performs the dilation of image f by the structuring element b. Dilation is a neighbourhood operator that compares locally b with f, according to an intersection rule. Since Dilation is a fundamental operator to the construction of all other morphological operators, it is also called an elementary operator of Mathematical Morphology. When f is a gray-scale image, b may be a flat or non-flat structuring element.

# Examples

## Example 1

```01. from ia870 import iadil
02. from ia870 import iabinary
03.
04.
05. f=iabinary([
06.    [0, 0, 0, 0, 0, 0, 1],
07.    [0, 1, 0, 0, 0, 0, 0],
08.    [0, 0, 0, 0, 1, 0, 0]])
09. b=iabinary([1, 1, 0])
10. print iadil(f,b).astype('int')
11. f=uint8([
12.    [ 0,   1,  2, 50,  4,  5],
13.    [ 2,   3,  4,  0,  0,  0],
14.    [12, 255, 14, 15, 16, 17]])
15. print iadil(f,b)```
```[[0 0 0 0 0 1 1]
[1 1 0 0 0 0 0]
[0 0 0 1 1 0 0]]
[[  1   2  50  50   5   5]
[  3   4   4   0   0   0]
[255 255  15  16  17  17]]
```

## Example 2

```01. from ia870 import iaimg2se
02. from ia870 import iagradm
03.
04.
05. f=iabinary( mmreadgray('blob.tif'))
06. bimg=iabinary( mmreadgray('blob1.tif'))
07. b=iaimg2se(bimg)
08. mmshow(f)
09. mmshow( iadil(f,b))
10. mmshow( iadil(f,b),iagradm(f))```

## Example 3

```01. from ia870 import iasedisk
02.
03.
04. f=mmreadgray('pcb_gray.tif')
05. b=iasedisk(5)
06. fdil = iadil(f,b)
07. mmshow(f)
08. mmshow(fdil)
09. mmshow(mmsurf(f))
10. mmshow(mmsurf(fdil))```

Where