Morphology Facade

mtlearn.morphology is the stable Python facade for morphology-tree construction, attribute computation, attribute groups, and attribute filters.

Stable morphology facade for mtlearn.

The current backend is mtlearn’s native _mtlearn extension. Keeping user code behind this module lets mtlearn swap morphology backends later without changing notebooks and high-level Python APIs.

class mtlearn.morphology.TreeType(*values)[source]

Bases: str, Enum

Public tree-type constants accepted by morphology and CFP layers.

MAX_TREE = 'max-tree'
MIN_TREE = 'min-tree'
TREE_OF_SHAPES = 'tree-of-shapes'
mtlearn.morphology.create_max_tree(image)[source]

Build a max-tree from a 2D numpy.uint8 image.

Parameters:

image – Contiguous or convertible 2D uint8 image.

Returns:

A WeightedMorphologicalTree facade backed by the native extension.

mtlearn.morphology.create_min_tree(image)[source]

Build a min-tree from a 2D numpy.uint8 image.

Parameters:

image – Contiguous or convertible 2D uint8 image.

Returns:

A WeightedMorphologicalTree facade backed by the native extension.

mtlearn.morphology.create_tree_of_shapes(image, interpolation=None, infinity_seed_row=0, infinity_seed_col=0)[source]

Build a tree of shapes from a 2D numpy.uint8 image.

Parameters:
  • image – Contiguous or convertible 2D uint8 image.

  • interpolation – Optional tree-of-shapes interpolation. Accepts ToSInterpolation values or string aliases such as "self-dual", "min4c-max8c", and "min8c-max4c".

  • infinity_seed_row (int) – Boundary infinity seed row used by the backend.

  • infinity_seed_col (int) – Boundary infinity seed column used by the backend.

Returns:

A WeightedMorphologicalTree facade backed by the native extension.

mtlearn.morphology.build_tree(image, tree_type, *, tos_interpolation=None, tos_infinity_seed_row=0, tos_infinity_seed_col=0)[source]

Build the morphology tree selected by tree_type.

Parameters:
  • image – Contiguous or convertible 2D uint8 image.

  • tree_type (str | TreeType) – TreeType value or one of the accepted string aliases for max-tree, min-tree, or tree of shapes.

  • tos_interpolation – Optional tree-of-shapes interpolation used only when tree_type selects TREE_OF_SHAPES.

  • tos_infinity_seed_row (int) – Boundary infinity seed row for tree of shapes.

  • tos_infinity_seed_col (int) – Boundary infinity seed column for tree of shapes.

Returns:

A WeightedMorphologicalTree facade.

Raises:

ValueError – If tree_type or tree-of-shapes interpolation is unknown.

mtlearn.morphology.normalize_tree_type(tree_type)[source]

Return the canonical string name for a public tree type.

Canonical values are "max-tree", "min-tree", and "tree-of-shapes".

Return type:

str

Parameters:

tree_type (str | TreeType)

mtlearn.morphology.normalize_tos_interpolation(interpolation=None)[source]

Return the native tree-of-shapes interpolation enum value.

None maps to ToSInterpolation.SelfDual.

mtlearn.morphology.compute_attributes(tree, attributes, *, output_space=_mtlearn.NodeIdSpace.MORPHOLOGICAL_TREE, dtype=None)[source]

Compute several scalar attributes or attribute groups for tree.

Parameters:
  • tree – A tree returned by this module.

  • attributes (Iterable) – Iterable containing AttributeType values, AttributeGroup values, or a mix of both.

  • output_space – Node-id space used by rows of the output buffer.

  • dtype – Optional NumPy-compatible floating dtype. Supported values are np.float32 and np.float64. None keeps the historical np.float32 default.

Returns:

(attribute_index, values) where attribute_index maps attribute names to output columns and values is a NumPy array with one row per node slot in the selected node-id space.

mtlearn.morphology.compute_single_attribute(tree, attribute, *, output_space=_mtlearn.NodeIdSpace.MORPHOLOGICAL_TREE, dtype=None)[source]

Compute one scalar attribute for tree.

Parameters:
  • tree – A tree returned by this module.

  • attribute – One AttributeType value.

  • output_space – Node-id space used by rows of the output buffer.

  • dtype – Optional NumPy-compatible floating dtype. Supported values are np.float32 and np.float64. None keeps the historical np.float32 default.

Returns:

A 1D NumPy array indexed by the selected node-id space.

mtlearn.morphology.describe_attribute(attribute)[source]

Return a human-readable description for one scalar attribute.

mtlearn.morphology.describe_all_attributes()[source]

Return descriptions for all public scalar attributes keyed by name.

mtlearn.morphology.expand_attribute_group(group)[source]

Expand one AttributeGroup into its scalar AttributeType members.

mtlearn.morphology.create_attribute_filter(tree)[source]

Create an attribute-filter helper bound to tree.

mtlearn.morphology.is_tree(value)[source]

Return whether value is a native mtlearn morphology tree handle.

Return type:

bool