|
MorphologicalAttributeFilters
Public API documentation
|
This guide documents the Higra-facing boundary of mmcfilters: importing a static hierarchy, preserving imported Higra node ids, exporting the current tree, and projecting node attributes to exported layouts.
For the underlying tree model, see Morphological Trees. For attribute buffer layout, see Attributes.
The library exposes two distinct Higra-related domains:
| Domain | Created by | Edit-stable | Main use |
|---|---|---|---|
| Preserved imported Higra domain | createFromHigraParent(...) | No | Original imported ids |
| Exported compact Higra domain | exportHigraHierarchy() | Snapshot only | Current live tree export |
NodeIdSpace::HIGRA refers only to the preserved imported domain. It does not mean "whatever `exportHigraHierarchy()` would produce now".
exportHigraHierarchy() always computes a new compact layout for the current live rooted tree. Use projectNodeValuesToExportedHigra(...) or Python project_node_values_to_exported_higra(...) when attributes must be aligned with that exported snapshot.
The compact Higra layout used by import and export is:
For an image domain with rows * cols proper parts:
[0, rows * cols);[rows * cols, parent.size());When exporting, proper parts are emitted in row-major order. Internal nodes are assigned compact ids from the live rooted tree. For max-trees and min-trees, the export order follows the tree altitude polarity with a deterministic post-order tie-breaker. Trees of shapes and self-dual residual trees derive the export direction from their local altitude relation.
The exported altitude array has the same length as the exported parent array. Leaf/proper-part altitudes are filled with the altitude of their owner node.
Use MorphologicalTreeFactory::createFromHigraParent(...) in C++:
The altitude type is typed in C++:
Python exposes the canonical 8-bit path:
Python altitude inputs must be integer sequences in [0, 255] or 1D C-contiguous np.uint8 arrays. C++ accepts any type satisfying the public AltitudeValue contract.
Max-tree and min-tree imports require adjacency metadata. In Python, pass radius; in C++, pass an AdjacencyRelation. Tree-of-shapes imports can omit component-tree adjacency.
SELF_DUAL_RESIDUAL_TREE is not accepted by the Higra import path; SDRT construction has its own factory path.
After import, the tree still uses the internal dense NodeId domain for normal tree operations. A preserved mapping from internal live nodes to the original Higra ids is available until the topology is edited:
For trees imported from the compact layout above, the internal slot associated with Higra internal id h starts as:
Do not rely on that arithmetic after edits. Safe public code should use getHigraNodeId(...) while the preserved domain is still valid.
Any topology mutation invalidates the preserved imported Higra domain. This includes safe mutators such as pruneNode(...) and mergeNodeIntoParent(...) and staged edit commits. After invalidation:
getNumHigraNodes() fails;NodeIdSpace::HIGRA attribute requests fail;getHigraNodeId(node) returns InvalidNode.Export still works after edits because it creates a new compact domain.
Attribute computation always runs internally in NodeIdSpace::MORPHOLOGICAL_TREE. Projection to NodeIdSpace::HIGRA is an API-boundary step.
Use preserved Higra output space when a consumer needs rows indexed by the original imported ids:
Live internal-node rows receive the values computed in the internal MorphologicalTree node-id space. Proper-part/leaf rows in the preserved imported Higra domain receive the same unit-component values used by compact Higra export.
Use exportHigraHierarchy() when a consumer needs the current live tree:
The exported layout is a fresh snapshot. It is valid for image-built trees, imported trees, and edited trees as long as the current topology is one rooted live component and the altitude buffer covers the internal node slots.
Dead internal slots are not exported. Export size is:
The exported parent and altitude arrays should be treated as a pair. If the tree is edited again, export again and reproject any attributes that must align with the new compact ids.
NodeIdSpace::HIGRA is not the right tool for exported snapshots. To align attributes with exportHigraHierarchy(), project a dense internal-node buffer:
Python exposes the same operation on WeightedMorphologicalTree:
For a single attribute:
The projection output follows the same [proper parts | live internal nodes] layout as the exported hierarchy. Internal-node rows are copied from the node-indexed input. Proper-part rows are filled with unit-component values for the requested attributes.
Examples of unit proper-part values:
AREA: 1;LEVEL and MEAN_LEVEL: the altitude of the proper-part owner;VOLUME: one pixel at the owner altitude;VARIANCE_LEVEL, GRAY_HEIGHT, and MAX_DIST: 0;Projection fails if:
WeightedTreeView<T> became stale after topology mutation.A common interoperability round trip is:
area_exported and area_imported_space use the same compact id layout after the round trip. Both paths fill proper-part rows with unit-component values.
Use preserved NodeIdSpace::HIGRA when:
Use exported Higra projection when:
exportHigraHierarchy() output.Use internal NodeIdSpace::MORPHOLOGICAL_TREE when:
mmcfilters;NodeId, proper parts, altitude, and edits.