# computeStabilityMeasure

MainPage

Description: This method computes the MSER stability measure of the max-tree nodes.

Equation:

Signature: sm = MaxTreeAlpha.computeStabilityMeasure(delta = 5)

Input:
• delta: int. Number of thresholds to be used to compute the MSER stability.
Output:
• sm: 1d-array, float. Array containing the MSER 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 computeStabilityMeasure(self, delta = 5):
4   """
5   This method computes the MSER stability measure of the Max-Tree nodes. The parameter delta
6   is the number of thresholds to be considered in the stability computation.
7   """
8
9   h = self.node_array[2,:]
10   parent = self.node_array[0,:]
11   area = self.node_array[3,:]
12   nlevels =  (h - h[parent]).astype(np.int32)
13   nlevels[0] = 1
14   hmin = int(h.min())
15   stability_measure = np.ones(self.node_array.shape[1], dtype = np.float)
16   nodes_list = (np.nonzero( (h >= (hmin + delta)))[0]).astype(np.int32)
17
18   self.compute_stability_measure_aux(parent, h, area, nlevels, nodes_list, stability_measure, delta, hmin)
19   return stability_measure
```

# Example

``` 1 from max_tree_alpha import MaxTreeAlpha
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 Bc = np.ones((3,3), dtype = bool)
10
11
12 mxt = MaxTreeAlpha(img,Bc)
13 sm = mxt.computeStabilityMeasure()
14 print "Stability measure:\n", sm
15
16 g= mxt.generateGraph()
17 mmgraphviz(g, title='Max-tree (node:h [area])')
```
```Stability measure:
[ 1.          1.          0.          1.          1.          1.
0.85714286  0.89473684  0.92857143  0.6         0.94736842  0.84210526
0.93333333  0.85714286  0.93333333  0.5         0.5       ]
```