# computeNodeGrayVar

MainPage

Description: This method computes the gray-level variance of the max-tree nodes.

Signature: gray_std = MorphTreeAlpha.computeNodeGrayVar()

Input:

Output:
• gray_var: 1d-array, float. Array containing the gray-level variance 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 computeNodeGrayVar(self,gray_avg = None):
4     """
5     This method computes the gray-level standard deviation of
6     the max-tree nodes.
7     """
8     if gray_avg == None :
9         gray_avg = self.computeNodeGrayAvg()
10
11     gray_var = np.zeros(self.node_array.shape[1], dtype = np.float)
12     squared_gray_avg = np.zeros(self.node_array.shape[1], dtype = np.float)
13     self.compute_node_gray_var_aux(self.node_array[0,:],self.node_array[2,:],self.node_array[3,:].copy(),squared_gray_avg)
14     squared_gray_avg = squared_gray_avg/self.node_array[3,:]
15     gray_var = (squared_gray_avg - gray_avg**2)
16     return gray_var
```

# Example

``` 1 from max_tree_alpha import MorphTreeAlpha
2 import numpy as np
3
4 img = np.array([[9,10, 3, 3, 3, 5, 8],
5                 [2, 0, 4, 0, 0, 0, 7],
6                 [8, 0, 5, 0, 6, 0, 9],
7                 [9, 0, 6, 0, 8, 4, 2]],dtype = np.uint8)
8
9 print img[img!=0].var()
10 Bc = np.ones((3,3), dtype = bool)
11
12
13 morph_tree = MorphTreeAlpha(img,Bc)
14 print 'Nodes gray-level variances:'
15 print morph_tree.computeNodeGrayVar()
16
17 g= morph_tree.generateGraph()
18 mmgraphviz(g, title='Morph-tree node:level[area]')
```
```6.5540166205
Nodes gray-level variances:
[ 11.89158163   6.55401662   0.25         5.33333333   2.7755102    5.36
2.1875       1.           0.25         0.25         0.           0.66666667
0.           0.           0.           0.           0.        ]
```