# 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
```

# 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
6 print img.shape
7 x,y = 100, 120 # Hand picked regional maximum
8 bin_img = np.zeros(img.shape,dtype = bool)
9 bin_img[x,y] = True
11 img2 = ia870.iagshow(img,bin_img)
13
14
15 Bc = np.ones((3,3), dtype = bool)
16 mxt = iamxt.MaxTreeAlpha(img,Bc)
17 node = mxt.node_index[x,y]
18
19 A = mxt.node_array[3,:]
20 levels,signature =  mxt.getSignature(A, node)
21 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'))
22
23 anc = mxt.getAncestors(int(node))[::-1]
24 area = A[anc]
```(256, 256)