Skip to main content

Morphological Trees Visualization

Project description

MorphoTreeViz – Morphological Trees Visualization

Interactive visualization of morphological trees.

Quick Start (import mtviz as viz)

import mtviz as viz

class Node:
    def __init__(self, id, level, area, children=None):
        self.id = id
        self.level = level
        self.area = area
        self.children = children or []

root = Node(1, 0, 10, [
    Node(2, 1, 5, [Node(4, 2, 3), Node(5, 2, 2)]),
    Node(3, 1, 5, [Node(6, 2, 1)])
])

pt = viz.PrintTree(lambda n: n.children, lambda n: f"{n.id}: {n.level}: {n.area}")
pt(root)

Color (optional)

  • Pass ANSI codes in color (e.g., "\x1b[40m\x1b[37m" for black background + white text).
  • If you use colorama in your project, you can pass Back.BLACK + Fore.WHITE.

Interactive Tree (viz.makePlotTree)

Use Bokeh to visualize and interact with the tree: hover tooltips, click actions, flood tools, and size/zoom controls.

import mtviz as viz
from bokeh.io import show, output_notebook

output_notebook()  # inline in Jupyter; use show(p) to open in browser

class Node:
    def __init__(self, id, level, area, children=None):
        self.id = id
        self.level = level
        self.area = area
        self.children = children or []

root = Node(1, 0, 10, [
    Node(2, 1, 5, [Node(4, 2, 3), Node(5, 2, 2)]),
    Node(3, 1, 5, [Node(6, 2, 1)])
])

p = viz.makePlotTree(
    root,
    lambda n: n.children,
    {
      "id:":      lambda n: n.id,
      "level:":   "level",
      "area:":    lambda n: n.area,
      "repCNPs":  lambda n: getattr(n, 'repCnps', []),
    },
    lambda n: n.id,
    node_size=18,
    flood_use=None,
)
show(p.panel)

Image Overlay + Flood

You can compose a figure with a grayscale image and an RGBA overlay, then link DrawTree’s flood tools.

import mtviz as viz
from bokeh.layouts import row, column

img = ...  # 2D numpy array (grayscale)
bundle_img = viz.makePlotImage(img)
p_img = bundle_img.panel
img_source = bundle_img.source
alpha_slider = bundle_img.controls[0]

p_tree = viz.makePlotTree(
  root,
  lambda n: n.children,
  { "id:": lambda n: n.id, "repCNPs": lambda n: getattr(n, 'repCnps', []) },
  lambda n: n.id,
  image_source=img_source,
  alpha_slider=alpha_slider,
  flood_use='floodThreshold',
  flood_params={'polarity': 255},
)
show(row(p_tree, column(alpha_slider, p_img)))

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

morphotreeviz-0.0.4.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

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

morphotreeviz-0.0.4-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file morphotreeviz-0.0.4.tar.gz.

File metadata

  • Download URL: morphotreeviz-0.0.4.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for morphotreeviz-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1a21f29c1d627beef5a14f10927b006bc1e69390e5147fc352fb29e877deeca0
MD5 2833f4eeaf1418d42cf5f7931f9de3b7
BLAKE2b-256 6942db37f4ab1ad3a3119950ec850fb90f15aaa24d1e6ffb682134e7ba38917f

See more details on using hashes here.

File details

Details for the file morphotreeviz-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: morphotreeviz-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for morphotreeviz-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 523a8faf7742c82a07a59f82c2fe2270547e2ce2fa4a79e98ad34b8a1da86f25
MD5 bbf6f42e09796465cb57dd7a01ee486b
BLAKE2b-256 0da2c0764b1af065b5cd46f3794b0d522fe2bac775ec870fbec71799be296c5c

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