computeExtinctionValues2

MainPage

Description: This method computes the shape extinction values of the second max-tree nodes.

Signature: ext = MaxTreeAlpha2.computeExtinctionValues2(attr)

Input:
  • attr: 1d-array float. Array containing the shape attributes of the max-tree nodes.
Output:
  • ext: 1d-array, float. Array containing the extinction values of the max-tree nodes. Non-leaf nodes have their value set to 0. Non-level roots have their value set to -1.

C++ Aux Function

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

Python Implementation

 1 import numpy as np
 2 
 3 def computeExtinctionValues2(self,attr):
 4     """
 5     This method computes the  extinction values of the second Max-Tree leaves.
 6     It receives the array attr containing the values to be analysed.
 7     """
 8 
 9     attr2 = attr + 1
10     par = self.node_array2[0,:].astype(np.int32)
11     ichmax = np.zeros_like(par)
12     achmax = np.zeros_like(attr2)
13     ext_values = np.zeros_like(attr2)
14     leaves = (np.nonzero(self.node_array2[1,:] == 0)[0]).astype(np.int32)
15     self.compute_extinction_values2_aux(par, attr2, leaves, ichmax,achmax, ext_values)
16     #ext_values[leaves] = ext_values[leaves] - 1
17     return ext_values

Example

 1 from iamxt.max_tree_alpha2 import MaxTreeAlpha2
 2 import numpy as np
 3 from iamxt.generate_graph import generateGraph
 4 
 5 
 6 img = adreadgray(find_attachment_file('iamxt/morph_tree_generate_cc_graph/synthetic01.png'))
 7 adshow(img)
 8 Bc = np.array([[1,1,1],[1,1,1],[1,1,1]], dtype = bool)
 9 print "\n2D structuring Element Bc:\n", Bc.astype(int)
10 
11 
12 mxt = MaxTreeAlpha2(img,Bc)
13 dx = mxt.node_array[7,:] - mxt.node_array[6,:] + 1
14 dy = mxt.node_array[10,:] - mxt.node_array[9,:] + 1
15 # Aspect ratio
16 temp = np.concatenate((dx.reshape(1,-1),dy.reshape(1,-1)), axis = 0)
17 den = temp.max(axis = 0)
18 num = temp.min(axis = 0)
19 attr = (1.0*num/den)
20 g= mxt.generateGraph(nodes_attr = attr)
21 mmgraphviz(g, title='Max-tree node:level[ar]')
22 
23 
24 
25 mxt.build2ndMaxTree(attr)
26 height = mxt.computeHeightFloat()
27 graph = generateGraph(mxt.node_array2[0,:],height)
28 mmgraphviz(graph,"Pixel oriented 2nd max-tree")
29 ext = mxt.computeExtinctionValues2(height)
30 print mxt.computeHeightFloat()
31 print "ext:"
32 print ext
2D structuring Element Bc:
[[1 1 1]
 [1 1 1]
 [1 1 1]]
[  3.34883721e-01   6.46258503e-02   2.17525499e-01   1.00000000e-20
   1.00000000e-20   9.34115980e-02   3.07343433e-02   1.00000000e-20
   1.00000000e-20]
ext:
[ 0.          0.          0.          1.          1.          0.          0.
  1.06462585  1.2175255 ]

/media/_xsb/iamxt/max_tree2_compute_extinction_values/GRVIZ25896_001.png

Max-tree node:level[ar]

/media/_xsb/iamxt/max_tree2_compute_extinction_values/GRVIZ25896_002.png

Pixel oriented 2nd max-tree