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,EnumPublic 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.uint8image.- Parameters:
image – Contiguous or convertible 2D uint8 image.
- Returns:
A
WeightedMorphologicalTreefacade backed by the native extension.
- mtlearn.morphology.create_min_tree(image)[source]¶
Build a min-tree from a 2D
numpy.uint8image.- Parameters:
image – Contiguous or convertible 2D uint8 image.
- Returns:
A
WeightedMorphologicalTreefacade 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.uint8image.- Parameters:
image – Contiguous or convertible 2D uint8 image.
interpolation – Optional tree-of-shapes interpolation. Accepts
ToSInterpolationvalues 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
WeightedMorphologicalTreefacade 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) –TreeTypevalue 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_typeselectsTREE_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
WeightedMorphologicalTreefacade.- Raises:
ValueError – If
tree_typeor 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.
Nonemaps toToSInterpolation.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 containingAttributeTypevalues,AttributeGroupvalues, 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.float32andnp.float64.Nonekeeps the historicalnp.float32default.
- Returns:
(attribute_index, values)whereattribute_indexmaps attribute names to output columns andvaluesis 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
AttributeTypevalue.output_space – Node-id space used by rows of the output buffer.
dtype – Optional NumPy-compatible floating dtype. Supported values are
np.float32andnp.float64.Nonekeeps the historicalnp.float32default.
- 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
AttributeGroupinto its scalarAttributeTypemembers.