Supervised (U-Net), unsupervised (Otsu/k-means/GMM), and label-free spectral-spatial (SOM) segmentation of scientific image stacks.
Project description
ct-segmentation-toolkit
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2401a2f390c582e9a67339ec29e271a294e4aaef23ee011313a581fdbb805a52
|
|
| MD5 |
ac08f117b2be3cb7d2ac54842a3a6cb4
|
|
| BLAKE2b-256 |
6c05ceb55518fbcb7f55e8cec3b19a5044b89e3015ffd6e85052397b38c32447
|
Provenance
The following attestation bundles were made for ct_segmentation_toolkit-0.2.0.tar.gz:
Publisher:
release.yml on crentb/ct-segmentation-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ct_segmentation_toolkit-0.2.0.tar.gz -
Subject digest:
2401a2f390c582e9a67339ec29e271a294e4aaef23ee011313a581fdbb805a52 - Sigstore transparency entry: 2187951765
- Sigstore integration time:
-
Permalink:
crentb/ct-segmentation-toolkit@bca77210f2cf7e1c33fcac85d7b486e77f7e53c6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/crentb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bca77210f2cf7e1c33fcac85d7b486e77f7e53c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ct_segmentation_toolkit-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ct_segmentation_toolkit-0.2.0-py3-none-any.whl
- Upload date:
- Size: 52.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6556c7cf5c4bcb22aac6eea7dca301c03f234ef51a05e6ee0f111d11077aae9e
|
|
| MD5 |
d815c04d94ef08e3e7db60b898755353
|
|
| BLAKE2b-256 |
a4efff8c75cebd0b9acb0ec9bd7f2bc546afe7e1065cdfa3411599ec2bde003b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ct_segmentation_toolkit-0.2.0-py3-none-any.whl -
Subject digest:
6556c7cf5c4bcb22aac6eea7dca301c03f234ef51a05e6ee0f111d11077aae9e - Sigstore transparency entry: 2187951800
- Sigstore integration time:
-
Permalink:
crentb/ct-segmentation-toolkit@bca77210f2cf7e1c33fcac85d7b486e77f7e53c6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/crentb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bca77210f2cf7e1c33fcac85d7b486e77f7e53c6 -
Trigger Event:
push
-
Statement type: