Skip to main content

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.

Release files for histoseg 0.1.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for histoseg 0.1.9.3
File Size Uploaded
histoseg-0.1.9.3.tar.gz 10.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for histoseg 0.1.9.3
File Interpreter ABI Platform
histoseg-0.1.9.3-py3-none-any.whl Python 3 none any Details

Total release size:10.6 MB

Release files / histoseg-0.1.9.3.tar.gz

Download URL histoseg-0.1.9.3.tar.gz
Size 10.5 MB
Tags Source
SHA-256 checksum
How to use checksums
cdd1ae0e35687ec867240de68fd90511afbd6e98eb9a5025d007bbe127154614
BLAKE2b-256 checksum
How to use checksums
3aaceb495df9c37f80e628bd1716c5e3ae58b4caf90ace4d3a064572887fbc0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Release files / histoseg-0.1.9.3-py3-none-any.whl

Download URL histoseg-0.1.9.3-py3-none-any.whl
Size 124.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
623a441159476a352fb808183094f7bbeaab34b53985368dc7f6e5b7cd708241
BLAKE2b-256 checksum
How to use checksums
eea400626c866aed5565f2051edcf0ec59118c33869a6688ac58c074e3519f52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9.3 This release

2 release files

0.1.9

2 release files

0.1.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page