Skip to main content

Supervised (U-Net), unsupervised (Otsu/k-means/GMM), and label-free spectral-spatial (SOM) segmentation of scientific image stacks.

Project description

ct-segmentation-toolkit

CI License: Apache 2.0 Python

Segmentation of scientific image stacks (e.g., synchrotron CT) across the full supervision spectrum, in one installable, tested package:

  • Supervised — a U-Net (ct_seg.model.UNetSegmentation) with training + inference.
  • Unsupervised — multi-Otsu, k-means, and GMM segmentation by intensity, with no training data needed.
  • Label-free spectral-spatial — a Self-Organizing-Map segmenter that describes each pixel by multi-scale density, structure-tensor orientation/coherence, a Gabor filter bank, and local variance, then clusters the SOM nodes. The same spectral-spatial feature engineering transfers directly to hyperspectral cubes.
  • Self-supervised denoising — a 2.5D Noise2Inverse denoiser (ct_seg.denoise): a no-skip U-Net trained from one noisy reconstruction (no clean reference), with a Laplacian Contrast Loss and edge-aware model selection. The author's own implementation of the N2I framework (upstream credit in ct_seg/denoise/ACKNOWLEDGMENTS.md).

Install

git clone https://github.com/crentb/ct-segmentation-toolkit.git
cd ct-segmentation-toolkit
python -m pip install -e ".[dev]"          # core + dev tools (pytest, ruff, black, mypy)
python -m pip install -e ".[viz]"          # optional: napari labeling + pyvista viewer
python -m pip install -e ".[mlops]"        # optional: MLflow experiment tracking
python -m pip install -e ".[denoise]"      # optional: N2I training (albumentations, PyYAML)

Python API

import numpy as np
from ct_seg import segment_kmeans, som_segment, UNetSegmentation

volume = np.random.rand(16, 256, 256).astype("float32")   # (slices, H, W) in [0, 1]

# Unsupervised intensity segmentation (no labels)
labels, info = segment_kmeans(volume, num_classes=4)

# Label-free spectral-spatial segmentation of a single slice
band_map = som_segment(volume[0], n_clusters=4)

# Supervised U-Net
model = UNetSegmentation(in_channels=1, num_classes=4)

Command line

# Unsupervised (otsu | kmeans | gmm)
python -m ct_seg.segment --input /path/to/tiffs --method kmeans --num_classes 4 --save_overlay

# Train a U-Net, then segment with it
python -m ct_seg.train   --images /path/to/tiffs --masks /path/to/masks --num_classes 4
python -m ct_seg.segment --input /path/to/tiffs --method unet --model SegOutput/best_model.pth --num_classes 4

(Interactive ct_seg.labeling (napari) and ct_seg.viewer (napari/pyvista) require the [viz] extra.)

Experiment tracking & profiling

Training integrates optional MLflow logging (run parameters, per-epoch loss/mIoU, and the best checkpoint). Install the extra and it logs automatically; without MLflow, tracking is a harmless no-op and training is unaffected:

pip install -e ".[mlops]"
python -m ct_seg.train --images ... --masks ... --num_classes 4   # logs to ./mlruns
mlflow ui                                                          # browse runs

A reproducible performance profile (forward / train-step latency, throughput, and peak GPU memory) is in docs/PERF.md:

python scripts/profile_unet.py --device cuda --sizes 256 512

Testing

pytest -m "not slow"      # fast suite (what CI runs)
pytest                    # everything

Status

The supervised, unsupervised, SOM, and Noise2Inverse denoising paths are functional and tested. The denoiser (ct_seg.denoise) is the author's own implementation of the N2I framework (upstream credit in ct_seg/denoise/ACKNOWLEDGMENTS.md). Related published work on deep-learning segmentation and self-supervised denoising of synchrotron CT is available as a preprint: https://ssrn.com/abstract=6805001

Acknowledgments

ct_seg.denoise implements the Noise2Inverse framework (Hendriksen, Pelt & Batenburg, IEEE Transactions on Computational Imaging, 2020; https://github.com/ahendriksen/noise2inverse). See ct_seg/denoise/ACKNOWLEDGMENTS.md.

License

Apache-2.0 — see LICENSE and NOTICE.

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

ct_segmentation_toolkit-0.2.0.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

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

ct_segmentation_toolkit-0.2.0-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file ct_segmentation_toolkit-0.2.0.tar.gz.

File metadata

  • Download URL: ct_segmentation_toolkit-0.2.0.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ct_segmentation_toolkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2401a2f390c582e9a67339ec29e271a294e4aaef23ee011313a581fdbb805a52
MD5 ac08f117b2be3cb7d2ac54842a3a6cb4
BLAKE2b-256 6c05ceb55518fbcb7f55e8cec3b19a5044b89e3015ffd6e85052397b38c32447

See more details on using hashes here.

Provenance

The following attestation bundles were made for ct_segmentation_toolkit-0.2.0.tar.gz:

Publisher: release.yml on crentb/ct-segmentation-toolkit

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

File details

Details for the file ct_segmentation_toolkit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ct_segmentation_toolkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6556c7cf5c4bcb22aac6eea7dca301c03f234ef51a05e6ee0f111d11077aae9e
MD5 d815c04d94ef08e3e7db60b898755353
BLAKE2b-256 a4efff8c75cebd0b9acb0ec9bd7f2bc546afe7e1065cdfa3411599ec2bde003b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ct_segmentation_toolkit-0.2.0-py3-none-any.whl:

Publisher: release.yml on crentb/ct-segmentation-toolkit

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