Skip to main content

Core C++/Python implementation of MorphoTreeAdjust for dynamic component-tree adjustment.

Project description

MorphoTreeAdjust

CI

MorphoTreeAdjust provides the core C++ and Python implementation for dynamic updates of component trees and connected alternating sequential filters (CASF). The repository is organized around a small public API, example programs, and developer tools for experiments, validation, and benchmarks.

Research Context

The repository is centered on dynamic update problems for component trees.

Let f be an image, and let T_f^min and T_f^max be the min-tree and max-tree of f.

We set:

  • S: a subtree in T_f^min
  • T_g^min: the min-tree obtained after pruning S from T_f^min
  • g: the image reconstructed from T_g^min
  • T_g^max: the max-tree of g

The central question is:

How to modify T_f^max to obtain T_g^max?

This is the basis for the dynamic primal/dual adjustment work and for CASF implementations derived from those structures.

Related papers:

  • Wonder Alves, Nicolas Passat, Dênnis José da Silva, Alexandre Morimitsu, Ronaldo F. Hashimoto. Efficient connected alternating sequential filters based on component trees. International Conference on Discrete Geometry and Mathematical Morphology (DGMM), November 2025, Groningen, Netherlands. hal-05163556
  • Wonder Alves, Nicolas Passat, Dênnis José da Silva, Alexandre Morimitsu, Ronaldo F. Hashimoto. Component tree: Update rather than rebuild. Journal of Mathematical Imaging and Vision (under review), 2026.

Quick Start

If you want the Python surface first, install it from PyPI:

python -m pip install morphoTreeAdjust

If you want the current repository version instead, install it from the repository root:

python -m pip install .

The package build is pyproject.toml-driven and uses scikit-build-core with CMake for the native extension.

Then use the public module:

import numpy as np
import morphoTreeAdjust as mta

image = np.array(
    [
        [4, 4, 2, 1],
        [4, 3, 2, 1],
        [5, 5, 2, 0],
        [5, 6, 6, 0],
    ],
    dtype=np.uint8,
)

adj = mta.AdjacencyRelation(image.shape[0], image.shape[1], 1.5)
maxtree = mta.DynamicComponentTree(image, True, adj)
mintree = mta.DynamicComponentTree(image, False, adj)

adjust = mta.DynamicComponentTreeAdjustment(mintree, maxtree)
adjust.refreshAttributes()

casf = mta.ComponentTreeCasf(image, "area", adj)
filtered = casf.filter([1, 2])

For a complete runnable script, see examples/core_python_api_example.py.

If you want a developer build with benchmarks and tools:

cmake -S dev-tools -B ../build/MorphoTreeAdjust/dev-tools
cmake --build ../build/MorphoTreeAdjust/dev-tools

If you want the install surface from the root project:

cmake -S . -B ../build/MorphoTreeAdjust/install \
  -DPYTHON_EXECUTABLE="$(python -c 'import sys; print(sys.executable)')"
cmake --build ../build/MorphoTreeAdjust/install
cmake --install ../build/MorphoTreeAdjust/install --prefix /tmp/mta-install

cmake --install publishes:

  • the Python package under lib/morphoTreeAdjust;
  • the public C++ headers under include/MorphoTreeAdjust when MTA_INSTALL_PUBLIC_CORE_HEADERS=ON.

Repository Layout

Recommended documentation entry points:

Developer Tools

Ad hoc debug binaries under dev-tools/tools/debug_*.cpp are excluded from the default developer build. Enable them explicitly when needed:

cmake -S dev-tools -B ../build/MorphoTreeAdjust/dev-tools \
  -DMTA_BUILD_DEBUG_TOOLS=ON
cmake --build ../build/MorphoTreeAdjust/dev-tools

Core benchmark example:

../build/MorphoTreeAdjust/dev-tools/benchmarks/jmiv2026_benchmark \
  --repeat 5 --warmup 1 --json --no-validate image1.png image2.png

dynamic_casf_apply

dynamic_casf_apply applies connected alternating sequential filters on grayscale images and compares the dynamic implementations against the naive rebuild-based baseline.

After building dev-tools, the executable is available at:

../build/MorphoTreeAdjust/dev-tools/tools/dynamic_casf_apply

Usage:

../build/MorphoTreeAdjust/dev-tools/tools/dynamic_casf_apply \
  [--mode dynamic-subtree|dynamic-leaf|naive|compare] \
  [--attribute area|bbox_width|bbox_height|bbox_diagonal] \
  [--radio-adj <radius>] \
  [--iter-timing] \
  [--no-output] \
  <input.png> [<output.png>] <threshold1> [threshold2 ...]

Modes:

  • dynamic-subtree: CASF with dynamic subtree-based updates;
  • dynamic-leaf: CASF with dynamic leaf-based updates;
  • naive: CASF by rebuilding the trees at every threshold;
  • compare: runs dynamic-subtree, dynamic-leaf, and naive, checks that outputs match, and prints a timing summary.

Attributes:

  • area
  • bbox_width
  • bbox_height
  • bbox_diagonal

Examples:

../build/MorphoTreeAdjust/dev-tools/tools/dynamic_casf_apply \
  --mode dynamic-subtree \
  --attribute area \
  cameraman.png cameraman_dynamic.png 64 128 256
../build/MorphoTreeAdjust/dev-tools/tools/dynamic_casf_apply \
  --mode compare \
  --attribute bbox_diagonal \
  --radio-adj 1.5 \
  --no-output \
  cameraman.png 64 128 256

Timing output:

  • Initialization time: dynamic setup cost before the threshold loop, including adjacency creation, max-tree/min-tree construction, attribute computer setup, initial attribute computation, and attribute binding;
  • Iteration time: accumulated threshold-loop time, excluding initialization and final reconstruction;
  • Reconstruction time: final image reconstruction time;
  • Total time: Initialization time + Iteration time + Reconstruction time.

For naive, Total time measures the full per-threshold rebuild-and-filter work. In compare mode, the reported dynamic totals include initialization so they are directly comparable to the naive baseline.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphotreeadjust-0.4.0.tar.gz (2.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

morphotreeadjust-0.4.0-cp312-cp312-win_amd64.whl (176.8 kB view details)

Uploaded CPython 3.12Windows x86-64

morphotreeadjust-0.4.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (224.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

morphotreeadjust-0.4.0-cp312-cp312-macosx_26_0_arm64.whl (165.8 kB view details)

Uploaded CPython 3.12macOS 26.0+ ARM64

morphotreeadjust-0.4.0-cp312-cp312-macosx_10_13_x86_64.whl (181.8 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

morphotreeadjust-0.4.0-cp311-cp311-win_amd64.whl (174.1 kB view details)

Uploaded CPython 3.11Windows x86-64

morphotreeadjust-0.4.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (224.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

morphotreeadjust-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl (179.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

morphotreeadjust-0.4.0-cp310-cp310-win_amd64.whl (173.3 kB view details)

Uploaded CPython 3.10Windows x86-64

morphotreeadjust-0.4.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (223.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

morphotreeadjust-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl (178.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file morphotreeadjust-0.4.0.tar.gz.

File metadata

  • Download URL: morphotreeadjust-0.4.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for morphotreeadjust-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c19a606c651c5677c5e4a23e5520986775ecf000e3875570585c9af75d20c593
MD5 b1d7c3e88fb93343d49e6de7e3bc85a2
BLAKE2b-256 70bf1866caef3b714af3bd94b6d252ec4043e2acc6e124518bce179550ee8c00

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ec74132b7eb0dc8b7fd2fec4c118f32c1f0c8bec632b902404ada82065aa92dc
MD5 f931cb5a7072b747bbca375cb402e62b
BLAKE2b-256 932cc5d153ff0cdd29b8a15b4132e796ca7214721d9f4355c4c1b363b6bc8c85

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3b44e517a2ddf6804b749e2f4af93c905b2479b5b5ef91e1e311d0dedc76cf15
MD5 0cffee166d70f993939c52b6e406cea5
BLAKE2b-256 6d220cfe0ae8afe53376bcc87f59ff89f2ca092510641a05d9bec0a69de2a62a

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp312-cp312-macosx_26_0_arm64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp312-cp312-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 c49e27ebf72d8e866706e0e53a93b982e3370bd15b140a53addaafc5669f4b39
MD5 f3672a653d68f721e33da74170babd23
BLAKE2b-256 f975322368b73e9a1c88d2417babe99a55106c762906730d8513b013e51917e0

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a5a90ea8f642c0bb23c306fadab22046e9d9bb0233556165bca1ba3c8eac46db
MD5 704ee2a11a0a44521a5525d90f386884
BLAKE2b-256 fe0c1b68e226a3bf055f8016abfc7bd183d34225fa9b423fb98f14de482bac97

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4b748c46b40a92f611471f26028bba090835d3e01e795383260da0da9b95fae8
MD5 50afe5cdf95e69a0b9e5da9431494aa1
BLAKE2b-256 34e1e5d6a2115ac0288e0449b2215c5c7d65091b66ba9cfa590985e0a7e8f3b9

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e3eda9fe63663d219695a44c70b628d0f76b284fc28843ea8c516503782a1c7
MD5 8ae36d4094f440f38ace59904d551982
BLAKE2b-256 2bc210a91c74054e48a65ab32207974a77fb81ca46f0926d91c10c7cbee9f178

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6b0934565d8d1a93ea0a0c547bcdb483974ee787a67f3a617265c9a319d7e385
MD5 983d15ad5ee6fc0b126c5c9abdb1a624
BLAKE2b-256 d8c19a9f1d8f4e96d41938583e8ec65f1c1b325062c205f8adf8cb241b9cec95

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a49c92866adc66f5ee0db730838b81455a8ce465f25c98c237f2e7f02faf2df0
MD5 2289e8fe52ebcd97a64838af76574b6d
BLAKE2b-256 c224b26e26eda9aab74d09039c4999cd4b00d959e3f756eb2d9e3abdf11bc34d

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f0a95186956c9a73b339f6b3c5640bb4c2e94d91e29eb91a38145896aad1be8
MD5 6f76a0e6a765bde7318e1a80cdf59221
BLAKE2b-256 90fed0002000312959b96a107bc6b294f7339b07f30899e3f0b74be40150b250

See more details on using hashes here.

File details

Details for the file morphotreeadjust-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dead44e2659250195722fd4e2379baef74dd089352c013ddaac5c2233d30afdc
MD5 e622e340187aaf6abde4ec9c0438183b
BLAKE2b-256 878c2cb4b255ed3deadf2be337fd5a8d6ad65d7a118c1da271e7b270e16afb82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page