getAncestors

MainPage

Description: This method returns the ancestors of node.

Signature: node_ancestors = MorphTreeAlpha.getAncestors(node)

Input:
  • node, int, node, of which its ancestors will be returned.

Output:

  • node_ancestors, 1d-array, int32. Array containing the ancestors of node.

C++ Aux Function

OK
OK [C/C++ extension is up-to-date]

Python Aux Function

Python Implementation

1 def getAncestors(self, node):
2   return self.get_ancestors_aux(node, self.node_array[0,:])

Example 01

 1 from morph_tree_alpha import MorphTreeAlpha
 2 import numpy as np
 3 
 4 img = np.array([[100, 100, 100, 0,   0,   0,   0,   0],\
 5                 [150, 150, 150, 150, 150, 150, 150, 150],\
 6                 [150, 160, 190, 150, 200, 200, 229, 150], \
 7                 [150, 185, 255, 150, 200, 230, 200, 150],\
 8                 [150, 180, 200, 150, 215, 229, 200, 150],\
 9                 [150, 150, 150, 150, 150, 150, 150, 150],\
10                 [50,  50,  0,   0,   0,   0,   0,   0]], dtype = np.uint8)
11 
12 
13 Bc = np.array([[0,1,0],\
14                [1,1,1],\
15                [0,1,0]], dtype = bool)
16 
17 
18 morph_tree = MorphTreeAlpha(img,Bc)
19 
20 
21 for i in xrange(morph_tree.node_array.shape[1]):
22   print "Ancestors of node %d:" %i
23   print morph_tree.getAncestors(i)
24   print
25 
26 
27 g= morph_tree.generateGraph()
28 mmgraphviz(g, title='Morph-tree')
Ancestors of node 0:
[0]

Ancestors of node 1:
[1 0]

Ancestors of node 2:
[2 1 0]

Ancestors of node 3:
[3 2 1 0]

Ancestors of node 4:
[4 3 2 1 0]

Ancestors of node 5:
[5 3 2 1 0]

Ancestors of node 6:
[6 5 3 2 1 0]

Ancestors of node 7:
[7 6 5 3 2 1 0]

Ancestors of node 8:
[8 7 6 5 3 2 1 0]

Ancestors of node 9:
[9 8 7 6 5 3 2 1 0]

Ancestors of node 10:
[10  9  8  7  6  5  3  2  1  0]

Ancestors of node 11:
[11  4  3  2  1  0]

Ancestors of node 12:
[12  4  3  2  1  0]

Ancestors of node 13:
[13 11  4  3  2  1  0]

Ancestors of node 14:
[14 13 11  4  3  2  1  0]
/media/_xsb/iamxt/morph_tree_get_ancestors/GRVIZ44277_001.png

Morph-tree