# computeEccentricity

MainPage

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

Signature: ecc,L1,L2 = MorphTreeAlpha.computeEccentricity()

Input:

Output:
• ecc: 1d-array, float. Array containing the eccentricity of the max-tree nodes.
• L1: 1d-array, float. Array containing the smaller axis of the ellipses fitted to the max-tree nodes.
• L2: 1d-array, float. Array containing the larger axis of the ellipses fitted to 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 computeEccentricity(self):
4     """
5     This method computes the eccentricity
6     of the max-tree nodes.
7     """
8
9     M20 = np.zeros((self.node_array.shape[1]),dtype = np.float)
10     M02 = np.zeros((self.node_array.shape[1]),dtype = np.float)
11     M11 = np.zeros((self.node_array.shape[1]),dtype = np.float)
12
13
14     par = self.node_array[0,:]
15     self.compute_eccentricity_aux(M20,M02,M11,par,self.node_index)
16
17     M00 = self.node_array[3,:]
18     xc = 1.0*self.node_array[5,:]/M00
19     yc = 1.0*self.node_array[8,:]/M00
20     m20 = 1.0*M20 /M00 - xc**2
21     m02 = 1.0*M02/M00 - yc**2
22     m11 = 1.0*M11/M00 - xc*yc
23     aux1 = (m20+m02)/2
24     aux2 = np.sqrt((m20-m02)**2 + 4*m11*m11)/2
25     L1 = aux1 - aux2
26     L2 = aux1 + aux2
27     ecc = L1/L2
28     #return m11,m20,m02
29     return L1,L2,ecc
```

# Example

``` 1 from max_tree_alpha import MorphTreeAlpha
2 import numpy as np
3
6
7 #img = np.array([[1,2,1],[2,3,2],[1,2,1]], dtype = np.uint8)
8
9 Bc = np.ones((3,3), dtype = bool)
10
11
12
13 morph_tree = MorphTreeAlpha(img,Bc)
14 L1,L2,ecc = morph_tree.computeEccentricity()
15 print 'ecc:'
16 print ecc
17 print 'L1'
18 print L1
19 print 'L2'
20 print L2
21
22 g= morph_tree.generateGraph()
23 mmgraphviz(g, title='Morph-tree node:level[area]')
```
```ecc:
[ 0.44237665  0.3275946   0.99171832  1.          0.92163233  0.79636509
0.88676393  0.92977426  0.90718589]
L1
[ 6816.25         546.43754017  4799.91666667   651.08332267   119.59404416
1420.43610332   214.33110872   205.18498368   238.75214904]
L2
[ 15408.25         1668.02976196   4840.            651.08332267
129.76329032   1783.64939036    241.70030001    220.68258095
263.17886129]
```