# Maximal Max-tree Simplification Methodology

``` 1 import iamxt
2 import numpy as np
3 import ia636
4
5 # Parameters of the method
6 option = "MSER" #Options "MSER" "T"
7 n = 8
8 attr = "area"
9
10 #Reading and displaying image
11 img = adreadgray('/awmedia/www/media/Attachments/iamxt-tutorial/interactive_maxtree01/MRI_sagittal.png')[:,::-1].copy()
12
13 Bc = np.ones((3,3),dtype = bool)
14 # Building the max-tree
15 mxt = iamxt.MaxTreeAlpha(img,Bc)
16 adshow(img, "Original Image (%d nodes)" % mxt.node_array.shape[1])
17
18
19 ext = mxt.computeExtinctionValues(mxt.node_array[3,:],attr)
20
21
22 # Result of the extinction filter
23 mxt.extinctionFilter(ext,n)
24 img_ef = mxt.getImage()
25 adshow(img_ef, 'Image after the Extinction %s Filter (%d nodes)' % (attr,mxt.node_array.shape[1]))
26
27
28 sm = mxt.computeStabilityMeasure()
29 mxt.mmsMSER(sm)
30 img_mms= mxt.getImage()
31 adshow(img_mms, 'Image after the EF + MMS-%s, (%d nodes)' % (option,mxt.node_array.shape[1]))
32
33
34 area = mxt.node_array[3,:]
35 mmgraphviz(mxt.generateCCGraph(parent_scale = True),"Resulting max-tree")
```

# Do it yourself

Apply the maximal max-tree simplification methodology to the license plate image in a way that all plate characters are preserved.

``` 1 import iamxt
2 import numpy as np
3 import ia636
4
5 # Parameters of the method
6 option = "T" #Options "MSER" "T"
7 n = 15
8 attr = "area"
9
10 #Reading and displaying image
11 img =adreadgray('/awmedia/www/media/Attachments/homeroberto/homeroberto_softwareX_bbox/lp.png')
12 adshow(img,'License plate image')
13
14 img_neg = 255 - img
15 #adshow(img_neg,'negative image')
16 Bc = np.ones((3,3),dtype = bool)
17 # Building the max-tree
18 mxt = iamxt.MaxTreeAlpha(img_neg,Bc)
19 adshow(img_neg, "negative Image (%d nodes)" % mxt.node_array.shape[1])
20
21
22 ext = mxt.computeExtinctionValues(mxt.node_array[3,:],attr)
23
24
25 # Result of the extinction filter
26 mxt.extinctionFilter(ext,n)
27 img_ef = mxt.getImage()
28 adshow(img_ef, 'Image after the Extinction %s Filter (%d nodes)' % (attr,mxt.node_array.shape[1]))
29
30
31 sm = mxt.computeStabilityMeasure()
32 mxt.mmsMSER(sm)
33 img_mms= mxt.getImage()
34 adshow(img_mms, 'Image after the EF + MMS-%s, (%d nodes)' % (option,mxt.node_array.shape[1]))
35
36
37 area = mxt.node_array[3,:]
38 mmgraphviz(mxt.generateCCGraph(parent_scale = True),"Resulting max-tree")
```