# computeHeight

MainPage

Description: This method computes the height attribute of the max-tree nodes.

Signature: height = MaxTreeAlpha.computeHeight()

Input:

Output:
• height: 1d-array, int32. Array containing the height attribute of the max-tree nodes.

# C++ Aux Function

```OK
```
```OK [C/C++ extension is up-to-date]
```

# Python Implementation

``` 1 import numpy as np
2
3 def computeHeight(self):
4     """
5     This method returns the height attribute of the max-tree nodes.
6     """
7     parent = self.node_array[0,:]
8     level  = self.node_array[2,:]
9     height = np.where(self.node_array[1,:] == 0, 1, 0).astype(np.int32)
10     #height = height.astype(np.int32)
11     delta = (level - level[parent]).astype(np.int32)
12     self.compute_height_aux(parent,delta,height)
13     return height
```

# Example

``` 1 from max_tree_alpha import MaxTreeAlpha
2 import numpy as np
3
4
5 img = np.array([[9,10, 3, 3, 3, 5, 8],
6                 [2, 0, 4, 0, 0, 0, 7],
7                 [8, 0, 5, 0, 6, 0, 9],
8                 [9, 0, 6, 0, 8, 4, 2]],dtype = np.uint8)
9
10 Bc = np.ones((3,3), dtype = bool)
11
12
13 mxt = MaxTreeAlpha(img,Bc)
14 height = mxt.computeHeight()
15
16 g= mxt.generateGraph(nodes_attr = height)
17 mmgraphviz(g, title='Max-tree node:h [height]')
```