Trees¶
This submodule contains the component tree classes.
Example
Simple creation of the max-tree of an image, compute the area attributes of the nodes and reconstruct a filtered image removing nodes with area less than 100 pixels:
>>> t = sap.MaxTree(image)
>>> area = t.get_attribute('area')
>>> filtered_image = t.reconstruct(area < 100)
-
class
sap.trees.
MaxTree
(image, adjacency=4)[source]¶ Bases:
sap.trees.Tree
Max tree class, the local maxima values of the image are in leafs.
- Parameters
image (ndarray) – The image to be represented by the tree structure.
adjacency (int) – The pixel connectivity to use during the tree creation. It determines the number of pixels to be taken into account in the neighborhood of each pixel. The allowed adjacency are 4 or 8. Default is 4.
Notes
Inherits all methods of Tree class.
-
class
sap.trees.
MinTree
(image, adjacency=4)[source]¶ Bases:
sap.trees.Tree
Min tree class, the local minima values of the image are in leafs.
- Parameters
image (ndarray) – The image to be represented by the tree structure.
adjacency (int) – The pixel connectivity to use during the tree creation. It determines the number of pixels to be taken into account in the neighborhood of each pixel. The allowed adjacency are 4 or 8. Default is 4.
Notes
Inherits all methods of Tree class.
-
class
sap.trees.
Tree
(image, adjacency)[source]¶ Bases:
object
Abstract class for tree representations of images.
Notes
You should not instantiate class Tree directly, use MaxTree or MinTree instead.
-
available_attributes
()[source]¶ Return a dictionary of available attributes and parameters.
- Returns
dict_of_attributes – The names of available attributes and parameters required. The names are keys (str) and the parameters are values (list of str) of the dictionary.
- Return type
dict
See also
get_attribute()
Return the attribute values of the tree nodes.
Notes
The list of available attributes is generated dynamically. It is dependent of higra’s installed version. For more details, please refer to higra documentation according to the appropriate higra’s version.
Example
>>> sap.Tree.available_attributes() {'area': ['vertex_area=None', 'leaf_graph=None'], 'compactness': ['area=None', 'contour_length=None', ...], ... 'volume': ['altitudes', 'area=None']}
-
get_attribute
(attribute_name, **kwargs)[source]¶ Get attribute values of the tree nodes.
- Parameters
attribute_name (str) – Name of the attribute (e.g. ‘area’, ‘compactness’, …)
- Returns
attribute_values – The values of attribute for each nodes.
- Return type
ndarray
See also
available_attributes()
Return the list of available attributes.
Notes
Some attributes require additional parameters. Please refer to available_attributes. If not stated, some additional parameters are automatically deducted. These deducted parameters are ‘altitudes’ and ‘vertex_weights’.
The available attributes depends of higra’s installed version. For further details Please refer to higra documentation according to the appropriate higra’s version.
Examples
>>> image = np.arange(20 * 50).reshape(20, 50) >>> t = sap.MaxTree(image) >>> t.get_attribute('area') array([ 1., 1., 1., ..., 998., 999., 1000.])
-
-
sap.trees.
available_attributes
()[source]¶ Return a dictionary of available attributes and parameters.
- Returns
dict_of_attributes – The names of available attributes and parameters required. The names are keys (str) and the parameters are values (list of str) of the dictionary.
- Return type
dict
See also
get_attribute()
Return the attribute values of the tree nodes.
Notes
The list of available attributes is generated dynamically. It is dependent of higra’s installed version. For more details, please refer to higra documentation according to the appropriate higra’s version.
Example
>>> sap.available_attributes() {'area': ['vertex_area=None', 'leaf_graph=None'], 'compactness': ['area=None', 'contour_length=None', ...], ... 'volume': ['altitudes', 'area=None']}