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.1.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.1-cp312-cp312-win_amd64.whl (176.7 kB view details)

Uploaded CPython 3.12Windows x86-64

morphotreeadjust-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (223.2 kB view details)

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

morphotreeadjust-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (175.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

morphotreeadjust-1.0.1-cp312-cp312-macosx_10_13_x86_64.whl (181.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

morphotreeadjust-1.0.1-cp311-cp311-win_amd64.whl (173.9 kB view details)

Uploaded CPython 3.11Windows x86-64

morphotreeadjust-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (223.2 kB view details)

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

morphotreeadjust-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (173.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

morphotreeadjust-1.0.1-cp311-cp311-macosx_10_9_x86_64.whl (179.0 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

morphotreeadjust-1.0.1-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.1-cp310-cp310-macosx_11_0_arm64.whl (172.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

morphotreeadjust-1.0.1-cp310-cp310-macosx_10_9_x86_64.whl (177.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: morphotreeadjust-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2ca7ab210bd50ddc8eb7b3d93f5e97f4cc624368b12569e74d87a9e6f4c06e5a
MD5 9dd61e0bf255fe50f3cda8fc1975eb27
BLAKE2b-256 1867db04a0c20962147c9a111db56efc22154dd25db6f229021d95136ec4561c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e0234cb3320a46dde19d36c6088fa9f9fbb1ea3476cc32b6fb25190fc9cf232b
MD5 713e26a197e0f2a088a220df7f02374a
BLAKE2b-256 7b96f2553874aa072bffc91838c3addd3c924f519aae019e1dc6f5204a449230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e46cecf26663625b9d256838d6ff6c1f9da501e121aa67b46c451c20b2cf6640
MD5 ebb0109574d536854e27458cebe61b1c
BLAKE2b-256 5c045d106aebf987936451771271f25593a56da19f52590aaf061d235a20fe26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ed21f61e9f772e9c5aac2cf8b5b170bcbe19c1dd249063dfbbfb01e9238552e6
MD5 6ded9e2ad4da5cc229e9c42dcf8a4117
BLAKE2b-256 120d3c89d0a3b48e53d5de49fca036e61b1f00893015aa892558571874c6cd59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9f9eb08e3bbd048ef9e016831056a1e4ee816025f5fba7e790d3cbb88fd1aad9
MD5 7eac06f146c8878bb622e05cf62ce112
BLAKE2b-256 9fe5dbb8f74d89df38c23ddd023c6a1a375e942a72f706b5be02ecbc3b8eee16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d20beec70cf78612e0798f29402af6caf882f288228e55be137cbe23b86fb0f1
MD5 e63a15561bf82ca48de61be9ba212d8a
BLAKE2b-256 cfccfb8500769dfccba54f363a336e839c63fa853958a39bb497d69a78984b6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 579b92e3c046130b9ac55cd0a237a3050de1ed87cab91a49a96e0d0361e48cb4
MD5 859321116f7fecdaa6ff2ca3d18dd609
BLAKE2b-256 cbd160bc264c7b6663468b4cae62ebcfff3e6111dafb1d8da40128dc86fe66b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1776333d0e82a4158e941c88e5fe14239bd7f2fd66635511288f61b47c65522f
MD5 271d2f979257d11f92e379859f89dc14
BLAKE2b-256 ba4e3b444dfd0ef28c84348a2119133787e5d456df3cddefcdac3b190033ff31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bd5b38e814415a19f06eff036ff8bef43d851d0827ce169c89fcfde1d0194a7a
MD5 cbd7153b2b3b1e4640019e51be06d385
BLAKE2b-256 d8b495c64d272718616e1cc1756165f794cdccf3748d807856076038f12a2b49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ced2b1682eab327de3bc1b92dc25ad501b81f9183493a22994e774be170083b7
MD5 07563c44258a3c3f1996cbea387d6947
BLAKE2b-256 7eb986e1a45b52cf6482c9226099cf4a1e657bb724c7bf22f19549dcc123061b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9fd6a3df72e130440b6a5f0462e9c0c9a261c556bee8effc47e17e9111a291f3
MD5 0ef53a25277b3890ff05cabffd3f7705
BLAKE2b-256 35a580267abf6df921662fcdfa07ead7556325020f7c637ca75303990a4ad904

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 287f9b6e78c33a53b055780ee71e4ead9f672f202ae571b95999a9447d5c4f02
MD5 81ccce1d12ca580a3a68b9dbf4aa6b08
BLAKE2b-256 dade8d1a066c53c97e040e0ddd115a9ffaf7b5bdc96c1913b67fff283f56b57d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for morphotreeadjust-1.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 10e85739c20a93f9c86cf91e2660b244b33426d919cf667e9f9860cf1e3baae2
MD5 6da784af664b46aa7af1a0bff832b228
BLAKE2b-256 94cb0e601c4359a4a1db71cf5029702cf0028a795aa3a4b4daf529412df1068d

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