# Synopse

Inf-reconstruction.

• y = iainfrec(m, g, bc=iasecross())
• y: Image output
• m: Image Marker image.
• g: Image Conditioning image.
• bc: Structuring Element Structuring element ( connectivity).
```01. import numpy as np
02. from iasecross import iasecross
03. import ia870 as MT
04.
05. def iainfrec_eq(f, g, bc=iasecross()):
06.     n = f.size
07.     y = MT.iacdil(f,g,bc,n)
08.     return y
09.
10. def iainfrec(m, f, Bc=iasecross()):
11.     h,w = Bc.shape
12.     hc,wc = h/2,w/2
13.     B = Bc.copy()
14.     off = np.transpose(B.nonzero()) - np.array([hc,wc])
15.     i = off[:,0] * w + off[:,1]
16.     Nids = MT.iaNlut(f.shape,off)
17.     x,y = np.where(Nids==f.size)
18.     Nids[x,y] = x
19.     Nids_pos = Nids[:,i<0] #de acordo com a convenção em Vincent93
20.     Nids_neg = Nids[:,i>0] #de acordo com a convenção em Vincent93
21.
22.     I = f.flatten()
23.     J = m.flatten()
24.     D = np.nonzero(J)[0]
25.     V = np.zeros(f.size,np.bool) #para controle de inserção na fila
26.     fila =[]
27.
28.     for p in D:
29.         Jq = J[p]
30.         for q in Nids_pos[p]:
31.             Jq = max(Jq,J[q])
32.             if (J[q] < J[p]) and (J[q] < I[q]) and ~V[p]:
33.                 fila.append(p)
34.                 V[p]=True
35.             J[p] = min(Jq,I[p])
36.
37.     for p in D[::-1]:
38.         Jq = J[p]
39.         for q in Nids_neg[p]:
40.             Jq = max(Jq,J[q])
41.             if (J[q] < J[p]) and (J[q] < I[q]) and ~V[p]:
42.                 fila.append(p)
43.                 V[p]=True
44.             J[p] = min(Jq,I[p])
45.
46.     while fila:
47.         p = fila.pop(0)
48.         for q in Nids[p]:
49.             if J[q]<J[p] and I[q]!=J[q]:
50.                 J[q] = min(J[p],I[q])
51.                 fila.append(q)
52.
53.     return J.reshape(f.shape)```

# Description

iainfrec creates the image y by an infinite number of recursive iterations (iterations until stability) of the dilation of f by bc conditioned to g. We say the y is the inf-reconstruction of g from the marker f. For algorithms and applications, see

# Examples

## Numeric

```01. import ia870 as MT
02. import ia636 as ia
03.
04. a = array([[1,0,1,0],
05.            [1,0,0,1],
06.            [0,0,1,1]],bool)
07. ma =array([[0,0,0,0],
08.            [1,0,0,1],
09.            [0,0,1,0]],bool)
10. b = MT.iainfrec(ma,a)
11. print 'b=\n',b *1```
```b=
[[1 0 0 0]
[1 0 0 1]
[0 0 1 1]]
```

## Binary image

```1. g=adreadgray('text_128.tif')
2. f=MT.iaero(g,MT.iaseline(9,90))
3. y=MT.iainfrec(f,g,MT.iasebox())

## Gray-scale image 1

```1. g=MT.ianeg( adreadgray('n2538.tif'))
2. f=MT.iaintersec(g,0)
3. f[20:60,30] = 255
4. y30=MT.iacdil(f,g,MT.iasebox(),30)
5. y=MT.iainfrec(f,g,MT.iasebox())

## Gray-scale image 2

```01. g=MT.ianeg( adreadgray('n2538.tif'))
02. m=MT.iaintersec(g,0)
03. m[100,10:-10] = 255
04. y30=MT.iacdil(m,g,MT.iasebox(),10)
05. t = time.time()
06. y=MT.iainfrec(m,g,MT.iasebox())
07. print 'Time:',time.time() - t,'seconds'
08. print 'info:',ia.iaimginfo(g)
```Time: 0.297026872635 seconds
info: <type 'numpy.ndarray'> (128, 128) uint8 66 231
```