prune

MainPage

Description: This method implements the pruning strategy.

Signature: MorphTreeAlpha.prune(to_prune)

Input:
  • to_prune, 1d-array bool. Array indicating whcih nodes should be pruned.

Output:

C++ Aux Function

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

Python Aux Function

Python Implementation

 1 import numpy as np
 2 
 3 def prune(self, to_prune):
 4     """
 5     Contracts entire branches of the tree. This is the prunning procedure to be
 6     used with increasing connected filters. If a node is indicated in to_prune, all its descendants
 7     should also be indicated in to_prune.
 8     """
 9     N = self.node_array.shape[1]
10     lut = np.arange(N, dtype = np.int32)
11     to_prune[0] = False
12     self.prune_aux(lut,to_prune.astype(np.int32), self.node_array[0,:], self.node_array[1,:])
13     #self.node_index = lut[self.node_index]
14     self.compact(to_prune,lut)
15     return self

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 
21 to_prune = morph_tree.node_array[3,:] < 6
22 
23 
24 g= morph_tree.generateGraph(keep = ~to_prune)
25 mmgraphviz(g, title='Morph-tree and its nodes marked to be pruned')
26 
27 morph_tree.prune(to_prune)
28 
29 
30 
31 g= morph_tree.generateGraph()
32 mmgraphviz(g, title='Morph-tree after the filtering procedure')
/media/_xsb/iamxt/morph_tree_prune/GRVIZ05839_001.png

Morph-tree and its nodes marked to be pruned

/media/_xsb/iamxt/morph_tree_prune/GRVIZ05839_002.png

Morph-tree after the filtering procedure