Skip to main content

Python toolkit for H&E image analysis, spatial contour analysis, and 3D contour reconstruction.

Project description

HistoSeg

PyPI Docs Publish to PyPI License: PolyForm Noncommercial 1.0.0

Python toolkit for H&E image analysis, spatial contour analysis, and 3D contour reconstruction.

HistoSeg has three public feature groups:

  • HE Analysis (histoseg.he) for image-based H&E tissue segmentation, neutral tissue partitioning, and aligned-image change detection.
  • Contour Analysis (histoseg.contour) for contour extraction from spatial/cell-coordinate data, including Pattern1 isolines and multi-structure Xenium exports.
  • 3D Analysis (histoseg.threed) for same-sample, multi-slice Xenium contour alignment and reconstruction workflows.

Full documentation: histoseg.readthedocs.io

When To Use Each Feature Group

Use HE Analysis when your input is an H&E image such as PNG, JPG, TIFF, or GeoTIFF and you want masks, overlays, heatmaps, GeoJSON polygons, or region tables.

Use Contour Analysis when your input is spatial cell-coordinate data such as Xenium cells.parquet plus cluster assignments, and you want geometry extracted from cell neighborhoods or selected cluster groups.

Use 3D Analysis when you are preparing for multi-slice Xenium contour reconstruction from the same sample. The first released workflow soft-aligns a hard-aligned moving contour GeoJSON to a fixed reference slice with a conservative TPS displacement field.

Installation

pip install -U histoseg

For local Hugging Face MedSAM-backed HE segmentation:

pip install -U "histoseg[he]"

For development:

git clone https://github.com/hutaobo/HistoSeg.git
cd HistoSeg
pip install -U pip
pip install -e ".[he]"

HE Analysis Quickstart

from histoseg.he import HESegmentationConfig, run_he_segmentation

result = run_he_segmentation(
    HESegmentationConfig(
        image="/path/to/he.png",
        out_dir="outputs/he_all_elements",
        task="all_elements",
        backend="heuristic",
        n_components=6,
    )
)

print(result.overlay_png)
print(result.geojson)
histoseg-he all-elements \
  --image /path/to/he.png \
  --out-dir outputs/he_all_elements \
  --backend heuristic

HE Analysis currently supports:

  • single: tissue foreground extraction, or user-prompted region extraction from boxes/points
  • all_elements: neutral tissue component partitioning (component_1, component_2, ...)
  • change: aligned before/after H&E change detection

Contour Analysis Quickstart

from histoseg.contour import Pattern1IsolineConfig, run_pattern1_isoline

cfg = Pattern1IsolineConfig(
    clusters_csv="/path/to/clusters.csv",
    cells_parquet="/path/to/cells.parquet",
    tissue_boundary_csv="/path/to/tissue_boundary.csv",
    out_dir="outputs/pattern1_isoline0p5",
    pattern1_clusters=(10, 23, 19, 27, 14, 20, 25, 26),
)

result = run_pattern1_isoline(cfg)
print(result.preview_png)
print(len(result.contours))
histoseg-contour pattern1 \
  --clusters-csv clusters.csv \
  --cells-parquet cells.parquet \
  --out-dir outputs/pattern1 \
  --pattern1-clusters 10,23,19

Contour Analysis currently supports:

  • Pattern1 isoline contour generation from clustered cell coordinates
  • multi-structure contour partitioning
  • Xenium Explorer annotation exports
  • Hugging Face dataset helper workflows for Xenium-style inputs

3D Analysis Quickstart

from histoseg.threed import (
    ThreeDContourReconstructionConfig,
    run_3d_contour_reconstruction,
)

cfg = ThreeDContourReconstructionConfig(
    fixed_geojson="slice_01.geojson",
    moving_hard_aligned_geojson="slice_02_hard_aligned_to_01.geojson",
    out_dir="outputs/3d_soft_alignment",
    group_property="structure",
    diagnostic_structure="Structure 5",
)

result = run_3d_contour_reconstruction(cfg)
print(result.soft_aligned_geojson)
print(result.diagnostic_report_png)
histoseg-3d reconstruct \
  --fixed-geojson slice_01.geojson \
  --moving-hard-aligned-geojson slice_02_hard_aligned_to_01.geojson \
  --out-dir outputs/3d_soft_alignment \
  --group-property structure \
  --diagnostic-structure "Structure 5"

3D Analysis currently performs the soft TPS registration/pre-reconstruction step. It does not yet generate a 3D mesh or volume.

Outputs

HistoSeg workflows write reviewable artifacts such as:

  • PNG previews and overlays
  • label maps and heatmaps
  • GeoJSON polygons
  • CSV/Parquet region or contour tables
  • params.json and metrics.json provenance files

Documentation

License

This project is distributed under the PolyForm Noncommercial 1.0.0 license. Academic and other noncommercial use is permitted. Any commercial use requires a separate commercial license from SPATHO AB. See LICENSE for details.

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

histoseg-0.1.9.3.tar.gz (10.5 MB view details)

Uploaded Source

Built Distribution

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

histoseg-0.1.9.3-py3-none-any.whl (124.4 kB view details)

Uploaded Python 3

File details

Details for the file histoseg-0.1.9.3.tar.gz.

File metadata

  • Download URL: histoseg-0.1.9.3.tar.gz
  • Upload date:
  • Size: 10.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for histoseg-0.1.9.3.tar.gz
Algorithm Hash digest
SHA256 cdd1ae0e35687ec867240de68fd90511afbd6e98eb9a5025d007bbe127154614
MD5 336ac518f1f1b4ea87bf2b7a5fadcf08
BLAKE2b-256 3aaceb495df9c37f80e628bd1716c5e3ae58b4caf90ace4d3a064572887fbc0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for histoseg-0.1.9.3.tar.gz:

Publisher: publish.yml on hutaobo/HistoSeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file histoseg-0.1.9.3-py3-none-any.whl.

File metadata

  • Download URL: histoseg-0.1.9.3-py3-none-any.whl
  • Upload date:
  • Size: 124.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for histoseg-0.1.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 623a441159476a352fb808183094f7bbeaab34b53985368dc7f6e5b7cd708241
MD5 ed776f70c6bc680da90ef6456d125b4a
BLAKE2b-256 eea400626c866aed5565f2051edcf0ec59118c33869a6688ac58c074e3519f52

See more details on using hashes here.

Provenance

The following attestation bundles were made for histoseg-0.1.9.3-py3-none-any.whl:

Publisher: publish.yml on hutaobo/HistoSeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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