# computeRR

MainPage

Description: This method computes the rectangularity ratio descriptor of each node of the tree.

2D Equation:

3D Equation:

Signature: rr = MorphTreeAlpha.computeRR()

Input:

Output:
• rr, 1d-array,float. Array containing the rectangularity ratio descriptor of each node of the tree

# Python Implementation

``` 1 def computeRR(self):
2     xmin,xmax = self.node_array[6,:], self.node_array[7,:] + 1
3     ymin,ymax = self.node_array[9,:], self.node_array[10,:] + 1
4     area = self.node_array[3,:]
5
6     if self.node_index.ndim == 2:
7         return 1.0*area/((xmax-xmin)*(ymax-ymin))
8     else:
9         zmin,zmax = self.node_array[12,:], self.node_array[13,:] + 1
10         return 1.0*area/((xmax-xmin)*(ymax-ymin)*(zmax-zmin))
```

# Example

``` 1 from morph_tree_alpha import MorphTreeAlpha
2 import numpy as np
3
4 np.set_printoptions(precision=4)
5
6 img = np.array([[100, 100, 100, 0,   0,   0,   0,   0],\
7                 [150, 150, 150, 150, 150, 150, 150, 150],\
8                 [150, 160, 190, 150, 200, 200, 229, 150], \
9                 [150, 185, 255, 150, 200, 230, 200, 150],\
10                 [150, 180, 200, 150, 215, 229, 200, 150],\
11                 [150, 150, 150, 150, 150, 150, 150, 150],\
12                 [50,  50,  0,   0,   0,   0,   0,   0]], dtype = np.uint8)
13
14
15 Bc = np.array([[0,1,0],\
16                [1,1,1],\
17                [0,1,0]], dtype = bool)
18
19
20 morph_tree = MorphTreeAlpha(img,Bc)
21
22 rr = morph_tree.computeRR()
23
24 print "Rectangularity ratio:"
25 print rr
```
```Rectangularity ratio:
[ 1.      0.8036  0.8958  1.      1.      1.      0.8333  0.6667  1.      1.
1.      0.75    1.      1.      1.    ]
```