# getSubBranches

MainPage

Description: This method computes the sub-branches of the tree. It is meant for internal use only.

Constructor signature: sb = MorphTreeAlpha.getSubBranches(sb_index)

Input:
• sb_index, int, index of the sub-branch.

Output:

• sb, 1d-array, int32. Sub-branch corresponding to sb_index.

# C++ Aux Function

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

# Python Implemementation

1 import numpy as np
2
3
4 def getSubBranches(self,sb_index = 0):
5
6     if self._sb_updated == False:
7         visited = np.zeros(self.node_array.shape[1], dtype = np.int32)
8         self._sb = np.zeros_like(visited)
9         self._cum_sb_hist = self.get_sub_branches_aux(self.node_array[0,:],\
10                                                       self.node_array[1,:],\
11                                                       self._sb, visited)
12         self._cum_sb_hist = np.concatenate((np.array([0],dtype = np.int32),\
13                                            self._cum_sb_hist),axis = 0)
14         self._sb_updated = True
15     return self._sb[self._cum_sb_hist[sb_index]:self._cum_sb_hist[sb_index+1]]

# Example

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 for i in xrange(6):
21     print "Sub-branch  %d:" %i
22     print morph_tree.getSubBranches(i)
23
24
25 g= morph_tree.generateGraph()
26 mmgraphviz(g, title='Morph-tree')
Sub-branch  0:
[14 13 11]
Sub-branch  1:
[12]
Sub-branch  2:
[10  9  8  7  6  5]
Sub-branch  3:
[4]
Sub-branch  4:
[3 2 1]
Sub-branch  5:
[0]