Skip to main content

SegSpy

CI Lint Docs License: MIT

📖 Read the documentation

Headless, backend-pluggable EM image segmentation library for HyperSpy.

SegSpy turns a HyperSpy Signal2D into a list of particle objects. It is microscope-generic (TEM/SEM) and particle-type-agnostic, shipping multiple interchangeable segmentation backends behind a uniform registry:

  • traditional_cv — CLAHE → black-hat → threshold → morphology → GrabCut refinement
  • sam — Meta SAM Auto-Mask Generator with a 5-stage post-filter

Installation

pip install SegSpy

For the SAM backend, install the optional extra:

pip install "SegSpy[sam]"   # adds segment-anything + torch

For development:

git clone https://github.com/VANvonZHANG/SegSpy.git
cd SegSpy
pip install -e ".[dev]"
pre-commit install

Quick start

import hyperspy.api as hs
from SegSpy import SegConfig, SegmentationRegistry, measure_morphology

signal = hs.load("image.dm4")
backend = SegmentationRegistry.get("traditional_cv")
mask = backend.segment(signal, SegConfig())
objects = backend.extract_objects(signal, mask, SegConfig())
for obj in objects:
    measure_morphology(obj, scale_nm=1.0)

CLI

SegSpy run image.dm4 --backend traditional_cv --output ./out

Writes <stem>_particles.csv (per-particle morphology metrics) and <stem>_labeled.png (a labelled mask) to the output directory.

Status

v0.1 — pure library + CLI, no GUI (deferred to a later release). See the CHANGELOG for details. Contributions welcome — see CONTRIBUTING.md.

Metadata

Release files for SegSpy 0.1.0

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

Source distribution (sdist)

Source distribution for SegSpy 0.1.0
File Size Uploaded
segspy-0.1.0.tar.gz 23.1 kB Details

Built distribution (wheel)

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

Total release size: 41.5 kB

Release files / segspy-0.1.0.tar.gz

Download URL segspy-0.1.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7cfacdc25415ff1a3585fc75dbb1114ffd7693058dc797607041f50d47fb3b60
BLAKE2b-256 checksum
How to use checksums
b0d0f0170862187d7f6a9eac9461ff44b0b12b564a89f41de9faf1ff82b539ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / segspy-0.1.0-py3-none-any.whl

Download URL segspy-0.1.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bb46816e2317e87e1d03d651f9314396c3918bc598a1a02b72cc02bdebc9dd0
BLAKE2b-256 checksum
How to use checksums
d4cd94905d8fd94812297a481b0d8764c8cb08bbb16e22bcbbe0587b76665df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

0.1.0 This release

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