##### Contents

MainPage

Description: This method implements the area difference filter.

Input:
• AD, int. Area difference threshold.

Output:

# C++ Aux Function

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

# Python Implementation

``` 1 import numpy as np
3     """
4     Implementation of the area difference filter proposed by Tavares et al.
5     """
6     n = self.node_array.shape[-1]
7     parent = self.node_array[0, :]
8     area = self.node_array[3, :]
9     to_keep = np.zeros(n, dtype = np.int32)
11     self.contractDR(to_keep>0)
12     return self
```

# Example

``` 1 import numpy as np
2 import ia636 as ia
3 from iamxt import MaxTreeAlpha
6 Bc = np.ones((3,3), dtype=np.bool)
7 mxt = MaxTreeAlpha(f, Bc)
8
9
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], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
14 AD = 10 # interactive parameter
16 print 'number of nodes after filtering: ',  mxt.node_array.shape[-1], ' | NL: ', np.count_nonzero(mxt.node_array[1,:])
```
```number of nodes before filtering:  2491  | NL:  2291
number of nodes after filtering:  1002  | NL:  803
```

# 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