computeNodeGrayAvg

MainPage

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

Signature: gray_avg = MorphTreeAlpha.computeNodeGrayAvg()

Input:

Output:
  • gray_avg: 1d-array, float. Array containing the gray-level average 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 computeNodeGrayAvg(self):
 4     """
 5     This method computes the gray-level average of
 6     the max-tree nodes.
 7     """
 8     gray_avg = np.zeros(self.node_array.shape[1], dtype = np.float)
 9 
10     self.compute_node_gray_avg_aux(self.node_array[0,:],self.node_array[2,:],self.node_array[3,:].copy(),gray_avg)
11     gray_avg = (gray_avg)/self.node_array[3,:]
12     return gray_avg

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.mean()
10 Bc = np.ones((3,3), dtype = bool)
11 
12 
13 morph_tree = MorphTreeAlpha(img,Bc)
14 print 'Nodes gray-level averages:'
15 print morph_tree.computeNodeGrayAvg()
16 
17 g= morph_tree.generateGraph()
18 mmgraphviz(g, title='Morph-tree node:level[area]')
3.96428571429
Nodes gray-level averages:
[  3.96428571   5.84210526   8.5          6.           6.71428571   6.8
   7.25         7.           5.5          9.5          6.           8.           8.
   9.           8.           9.          10.        ]
/media/_xsb/iamxt/morph_tree_compute_node_gray_average/GRVIZ66070_001.png

Morph-tree node:level[area]