# vmax

MainPage

Description: This method implements the vmax filter. It removes all components with volume smaller than a threshold vol.

Constructor signature: MaxTreeAlpha.vmax(vol)

Input:
• vol, int. Volume threshold value. Every node with volume < vol will be contracted.

Output:

# Python Implementation

``` 1 def vmax(self, vol,V = None):
2     """
3     This method implemnets the vmax filter
4     """
5     vol = vol + 1
6     area = self.node_array[3,:]
7     level = self.node_array[2,:]
8     parent = self.node_array[0,:]
9     if V == None:
10         child_volume = self.computeVolume() - area
11     else:
12         child_volume = V - area
13
14     total_volume = child_volume + (level - level[parent])*area
15     area = area[total_volume >= vol]
16     self.prune(total_volume < vol)
17
18     child_volume = child_volume[total_volume >= vol]
19     self.node_array[2,child_volume < vol] -= (vol - child_volume[child_volume < vol]) / area[child_volume < vol]
20     return self
```

# Example

``` 1 from max_tree_alpha import MaxTreeAlpha
2 import numpy as np
3
4 img = np.array([[100, 100, 100, 0,   0,   0,   0,   0],\
5                 [150, 150, 150, 150, 150, 150, 150, 150],\
6                 [150, 160, 190, 150, 200, 200, 229, 150], \
7                 [150, 185, 255, 150, 200, 230, 200, 150],\
8                 [150, 180, 200, 150, 215, 229, 200, 150],\
9                 [150, 150, 150, 150, 150, 150, 150, 150],\
10                 [50,  50,  0,   0,   0,   0,   0,   0]], dtype = np.uint8)
11
12
13 Bc = np.array([[0,1,0],\
14                [1,1,1],\
15                [0,1,0]], dtype = bool)
16
17
18 mxt = MaxTreeAlpha(img,Bc)
19
20 g= mxt.generateGraph()
21 mmgraphviz(g, title='Max-tree')
22
23 mxt.vmax(60)
24 g= mxt.generateGraph()
25 mmgraphviz(g, title='Max-tree after filtering the nodes with volume < 60')
```