# Max-tree signature

``` 1 import numpy as np
2 import iamxt
3 import ia870
4 import ia636
5
7
8 x,y = 168,305 # Hand picked regional maximum
9 bin_img = np.zeros(img.shape,dtype = bool)
10 bin_img[x,y] = True
12 img2 = ia870.iagshow(img,bin_img)
13 adshow(img2,'Mona Lisa image with a regional maxima highlighted')
14
15
16 # Max-tree construction
17 Bc = np.ones((3,3), dtype = bool)
18 mxt = iamxt.MaxTreeAlpha(img,Bc)
19 node = mxt.node_index[x,y]
20
21 # Area signature
22 A = mxt.node_array[3,:]
23 levels,signature =  mxt.getSignature(A, node)
24 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'))
25
26
27 #Getting the nodes before and after the largest drop
28 anc = mxt.getAncestors(int(node))[::-1]
29 area = A[anc]
32 max1 = indexes[-1]
33 anc_max1 = [anc[max1],anc[max1+1]]
34
35
36 adshow(mxt.recConnectedComponent(anc_max1[0]),"Node %d, area %d" %(anc_max1[0],A[anc_max1[0]]))
37 adshow(mxt.recConnectedComponent(anc_max1[1]),"Node %d, area %d" %(anc_max1[1],A[anc_max1[1]]))
```

# Do it yourself! #1

Try to segment the brain from the skull using area signature analysis.

``` 1 import numpy as np
2 import iamxt
3
6
7 #x,y = 120,112 # Hand picked regional maximum
8 x,y = 134,157 # Hand picked regional maximum
9 bin_img = np.zeros(img.shape,dtype = bool)
10 bin_img[x,y] = True
12 img2 = ia870.iagshow(img,bin_img)
13 adshow(img2,'brain image with a regional maxima highlighted')
14
15
16 # Max-tree construction
17 Bc = np.ones((3,3), dtype = bool)
18 mxt = iamxt.MaxTreeAlpha(img,Bc)
19 node = mxt.node_index[x,y]
20
21 # Area signature
22 A = mxt.node_array[3,:]
23 levels,signature =  mxt.getSignature(A, node)
24 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'))
25
26 #Getting the nodes before and after the largest drop
27 anc = mxt.getAncestors(int(node))[::-1]
28 area = A[anc]
31
32 #for..5 quedas
33
34 max1 = indexes[-1]
35 anc_max1 = [anc[max1],anc[max1+1]]
36
37
38 adshow(mxt.recConnectedComponent(anc_max1[0]),"Node %d, area %d" %(anc_max1[0],A[anc_max1[0]]))
39 adshow(mxt.recConnectedComponent(anc_max1[1]),"Node %d, area %d" %(anc_max1[1],A[anc_max1[1]]))
```

# Do it yourself! #2

Try to segment the brain from the skull using area signature analysis.

```1 import numpy as np
2 import iamxt
3