Morphology Facade

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

Morphology facade backed by the native _mtlearn extension.

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 ValuedMorphologicalTree 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 ValuedMorphologicalTree 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 ValuedMorphologicalTree 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 ValuedMorphologicalTree 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.SELF_DUAL.

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

Compute a scalar as a 1D array, or a group or iterable as (layout, values).

Attributes and groups accept enum values or canonical symbolic names. The default dtype is float32; float64 is also supported.

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