##### Contents

MainPage

Description: This method implements the progressive area difference filter.

Input:
• AD, int. Area difference threshold.

Output:

# C++ Aux Function

```OK
```
```1 void prog_area_difference_aux_c(int AD, int DIM1, int *INPLACE_ARRAY1,int DIM1, int *INPLACE_ARRAY1, int DIM1, int *INPLACE_ARRAY1, int DIM1,
2                                 int *INPLACE_ARRAY1, int DIM1, int *INPLACE_ARRAY1);
```
```OK [C/C++ extension is up-to-date]
```

# Python Implementation

``` 1 import numpy as np
2
4     parent = self.node_array[0, :]
5     area = self.node_array[3, :]
6     to_keep = np.zeros(self.node_array.shape[-1], np.int32)
7     visited = np.zeros_like(to_keep)
8     leaves = (np.nonzero(self.node_array[1,:] == 0)[0]).astype(np.int32)
10     self.contractDR(to_keep>0)
11     return self
```
``` 1 import numpy as np
2 import ia636 as ia
3 from iamxt import MaxTreeAlpha
4 from time import time
5
8 Bc = np.ones((3,3), dtype=np.bool)
9 mxt = MaxTreeAlpha(f, Bc)
10 V = mxt.computeVolume()
11 Vext = mxt.computeExtinctionValues(V,"volume")
12 mxt.extinctionFilter(Vext, 200)
13 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1]
14 AD = 15 # interactive parameter
17 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1]
```
```number of nodes before filtering:  2978
number of nodes after filtering:  822
```

# Example MRI

``` 1 f = adreadgray('homeluistavares/luistavares_app_seg3/sagittal-agnalda.png')
3 Bc = np.ones((3,3), dtype=np.bool)
4 mxt = MaxTreeAlpha(f, Bc)
5 V = mxt.computeVolume()
6 Vext = mxt.computeExtinctionValues(V,"volume")
7 mxt.extinctionFilter(Vext, 200)
8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
9
10 AD = 11 # interactive parameter
12 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
```
```number of nodes before filtering:  3441  | NL:  3241
number of nodes after filtering:  1425  | NL:  1245
```

# Example - Cameraman

``` 1 f = adreadgray('cameraman.tif')
3 Bc = np.ones((3,3), dtype=np.bool)
4 mxt = MaxTreeAlpha(f, Bc)
5 V = mxt.computeVolume()
6 Vext = mxt.computeExtinctionValues(V,"volume")
7 mxt.extinctionFilter(Vext, 200)
8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
9
10 AD = 10 # interactive parameter
12 print 'number of nodes after filtering: ', mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
```
```number of nodes before filtering:  3925  | NL:  3725
number of nodes after filtering:  2065  | NL:  1879
```

# Example - Sintetic image

``` 1 f = adreadgray('homeluistavares/sintetic_image/f.png')
3 Bc = np.ones((3,3), dtype=np.bool)
4 mxt = MaxTreeAlpha(f, Bc)
5 V = mxt.computeVolume()
6 Vext = mxt.computeExtinctionValues(V,"volume")
7 mxt.extinctionFilter(Vext, 200)
8 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
9
10 AD = 20000 # interactive parameter
12 print 'number of nodes after filtering: ', mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
```
```number of nodes before filtering:  9  | NL:  4
number of nodes after filtering:  7  | NL:  2
```

# Example Gaussian image

``` 1 import ia636 as ia
2
3 f = ia.iagaussian((200,200), np.transpose([[100,100]]), [[10*10,0],[0,20*20]])
4 f = ia.ianormalize(f, [0,255]).astype(uint8)
6 Bc = np.ones((3,3), dtype=np.bool)
7 mxt = MaxTreeAlpha(f, Bc)
8 V = mxt.computeVolume()
9 Vext = mxt.computeExtinctionValues(V,"volume")
10 mxt.extinctionFilter(Vext, 200)
11 print 'number of nodes before filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
12
13 AD = 20 # interactive parameter
```number of nodes before filtering:  230  | NL:  229