Skip to main content

Core C++/Python implementation of MorphoTreeAdjust for dual min/max tree incremental filtering.

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 dual min/max tree incremental filtering 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.DualMinMaxTreeIncrementalFilter(mintree, maxtree)

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-1.0.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-1.0.0-cp312-cp312-win_amd64.whl (176.5 kB view details)

Uploaded CPython 3.12Windows x86-64

morphotreeadjust-1.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (223.4 kB view details)

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

morphotreeadjust-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (175.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

morphotreeadjust-1.0.0-cp312-cp312-macosx_10_13_x86_64.whl (180.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

morphotreeadjust-1.0.0-cp311-cp311-win_amd64.whl (173.8 kB view details)

Uploaded CPython 3.11Windows x86-64

morphotreeadjust-1.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (223.3 kB view details)

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

morphotreeadjust-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (173.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

morphotreeadjust-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl (178.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

morphotreeadjust-1.0.0-cp310-cp310-win_amd64.whl (173.2 kB view details)

Uploaded CPython 3.10Windows x86-64

morphotreeadjust-1.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (222.3 kB view details)

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

morphotreeadjust-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (172.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

morphotreeadjust-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl (177.4 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: morphotreeadjust-1.0.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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cdc7edc8e3aff70aef88e8ee8560c10050671325da1cadf120883cadbc126acf
MD5 f693644d99b28d7966694422cc38046e
BLAKE2b-256 cf9975e202c20304828587ce495f2e5cd719a459e7b525f70a7dc9b77d181d2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6867512384011ad067f062959c12bd0b1b83063aa7ae85820aa131db6038093d
MD5 ba3baa2c80d68754bfb17e99dda7d311
BLAKE2b-256 99e633f99f475b1ba462a994a338977004d9bb373d24accc8578f9384320e374

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d069598b1198274310f67fdb4269295cb84990f51aff843ee5a7d505c579ac3
MD5 c2a4c7d39a3f748e75cfa7013d2dc044
BLAKE2b-256 b49e5503476f688a829ce2ab6952e8401403b4cd9f2009cd29f66372964f8a9e

See more details on using hashes here.

File details

Details for the file morphotreeadjust-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e2a7b4fbb2586eb4d66153a1a4095cd5e421dee317f26c25fd873565d084fe8
MD5 13d1b929f9919a1a720cecf0f5e69bf6
BLAKE2b-256 f73206f461b58b7aafa8adc60ee926410e458c5c56c7e77e93473dd5d4efd611

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 c65afea90a86b3c1b250986035f28d0db4c42fea6d1d8e062dc2f91c4cddaaa3
MD5 f3f67444df6ff07395b433293fc70349
BLAKE2b-256 3fc7d9138765d1bdc587ce918e557d492c41860ca4ec1769590a10a976da0afd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b0274fd9fa6a47a7eec665f4e072025cf4fec242c3f233fed29e8f874b60e0c8
MD5 1c40b32e549107a6bef3604004958040
BLAKE2b-256 24d2aed00c591346dbaf5faf48799f01f3bb4801caeb7246df189ae58c5eca27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f107c881f0f2b3df05fccaef49a1db9172435f1cc00ae450f893cfaf30f5d3c8
MD5 99d5ce0549093b359dd06988b58b83a9
BLAKE2b-256 7a5d21e51b0454ec933c67911f9ef1b6de59bcd37da11b926a4f4258cb0dca1e

See more details on using hashes here.

File details

Details for the file morphotreeadjust-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c321bc2478c4141034c4535b49323ead50d000e94f539f957ce96efae63f9891
MD5 76aaed75dffc120626e27483e9ce9d31
BLAKE2b-256 f81fd291137b3ac2fccebaab799b00e63f1dd88162751691dc1ff9b87f119746

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4a4e0a94f821e1d8abec0524df53aa78a7ba56746965928e45e2a1ed329af000
MD5 42eb5e7277f704ac7ce1ac816655450b
BLAKE2b-256 63aab793b5ad53b6d6c9b96c3be21e152ba22ca60d74dce2f869c2260df3a7df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a5b09e692c89b5c6bf2f0220c6c50a4f5dcc7da267d89e92d35fd3bf794996a8
MD5 ebbd01e96b26201d9fbc61a6abb28c82
BLAKE2b-256 e9428c32e3fd4e683e146007bf40bb694c039b18cd91dbe4008f55902ab1c882

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2100dd7dc548a3ef9219118fd4406dab1eb7e2cc062e03d85e9ad37a410be7c6
MD5 78c4cd7cec5e06a0fe1d3a160908b8eb
BLAKE2b-256 8e8e532d0c4d0cc9a302ae4a15723cb23a74d5bf8ab418cfe5d714cecc6af593

See more details on using hashes here.

File details

Details for the file morphotreeadjust-1.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7760b7b3973230f38d28b57f1076cae76f5d2cdf67f01e19d22c68cc8c85b6f
MD5 b4d6202851b4cd60a284f88e1bfc2ba0
BLAKE2b-256 727286d843da8f6aef7aa72896aba6400f3214be37b9d233509ab92ea89fec3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 404b579bdc6f02f164e7df810abc517ff0906fefbeb41b141b5f1bf802380d61
MD5 75c76a3079dbce4892cf99d95d26e494
BLAKE2b-256 8d57ad8bae073e71fce573ce95dcc950cbce64dacd2d0f627c2c7728598c8a11

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