computeExtinctionValues

MainPage

Description: This method computes the height, area or volume extinction values of the max-tree nodes.

Signature: ext = MaxTreeAlpha.computeExtinctionValues(attrib_orig, opt = "area")

Input:
  • attrib_orig: 1d-array int32. Array containing either the height, area or volume attribute of the max-tree nodes.
  • opt: str. Option containing the extinction values to be computed ("height", "area" or "volume").
Output:
  • ext: 1d-array, float. Array containing the extinction values of the max-tree nodes. Non-leaf nodes have their value set to 0.

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 computeExtinctionValues(self,attrib_orig, opt = "area"):
 4     """
 5     This method computes the "hegiht", "area", "volume" or "bb" extinction
 6     values of the Max-Tree leaves. It receives the array attrib containing
 7     the values to be analysed and a string with the attribute option, since
 8     for "height" and "volume" attributes the hidden layers of the composite
 9     nodes have to be considered.
10     """
11 
12     attrib = attrib_orig.copy()
13     parent = self.node_array[0,:]
14     nchild = self.node_array[1,:]
15     h = self.node_array[2,:]
16     area = self.node_array[3,:]
17     nlevels = h - h[parent]
18     composite_nodes = nlevels > 1
19     if opt == "area":
20         pass
21     elif opt == "height":
22         attrib[composite_nodes] = attrib[composite_nodes] + \
23                                   (nlevels[composite_nodes] - 1)
24     elif opt == "volume":
25         attrib[composite_nodes] = attrib[composite_nodes] +\
26                                   (nlevels[composite_nodes] - 1)\
27                                   *area[composite_nodes]
28     else:
29         print "Invalid Option"
30         return
31 
32     ichmax = np.zeros_like(parent)
33     achmax = np.zeros_like(parent)
34     ext_values = np.zeros_like(parent)
35     leaves = (np.nonzero(nchild == 0)[0]).astype(np.int32)
36     self.compute_extinction_values_aux(parent, attrib, leaves, ichmax,\
37                                        achmax, ext_values)
38     return ext_values

Example

 1 from max_tree_alpha import MaxTreeAlpha
 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 Bc = np.ones((3,3), dtype = bool)
10 
11 
12 mxt = MaxTreeAlpha(img,Bc)

Height extinction

1 height = mxt.computeHeight()
2 Hext = mxt.computeExtinctionValues(height,"height")
3 
4 
5 g= mxt.generateGraph(nodes_attr = height)
6 mmgraphviz(g, title='Max-tree (node:h [height])')
7 
8 g2 = mxt.generateGraph(nodes_attr = Hext)
9 mmgraphviz(g2, title='Max-tree (node:h [Hext])')
/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_001.png

Max-tree (node:h [height])

/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_002.png

Max-tree (node:h [Hext])

Area extinction

1 area = mxt.node_array[3,:]
2 Aext = mxt.computeExtinctionValues(area,"area")
3 
4 
5 g= mxt.generateGraph(nodes_attr = area)
6 mmgraphviz(g, title='Max-tree (node:h [area])')
7 
8 g2 = mxt.generateGraph(nodes_attr = Aext)
9 mmgraphviz(g2, title='Max-tree (node:h [Aext])')
/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_003.png

Max-tree (node:h [area])

/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_004.png

Max-tree (node:h [Aext])

Volume extinction

1 volume = mxt.computeVolume()
2 Vext = mxt.computeExtinctionValues(volume,"volume")
3 
4 
5 g= mxt.generateGraph(nodes_attr = volume)
6 mmgraphviz(g, title='Max-tree (node:h [volume])')
7 
8 g2 = mxt.generateGraph(nodes_attr = Vext)
9 mmgraphviz(g2, title='Max-tree (node:h [Vext])')
/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_005.png

Max-tree (node:h [volume])

/media/_xsb/iamxt/max_tree_compute_extinction_values/GRVIZ96289_006.png

Max-tree (node:h [Vext])