Metadata-Version: 2.4
Name: SegSpy
Version: 0.1.0
Summary: Headless, backend-pluggable EM image segmentation library for HyperSpy
Author-email: Fan Zhang <vanvonzhang@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/VANvonZHANG/SegSpy
Project-URL: Repository, https://github.com/VANvonZHANG/SegSpy
Project-URL: Bug Tracker, https://github.com/VANvonZHANG/SegSpy/issues
Project-URL: Changelog, https://github.com/VANvonZHANG/SegSpy/blob/main/CHANGELOG.md
Keywords: microscopy,hyperspy,segmentation,tem,sem,image-analysis,particle,electron-microscopy
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: opencv-python
Requires-Dist: scipy
Requires-Dist: hyperspy>=2.0
Provides-Extra: sam
Requires-Dist: segment-anything; extra == "sam"
Requires-Dist: torch; extra == "sam"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: ruff>=0.6.0; extra == "dev"
Requires-Dist: pre-commit>=3.0; extra == "dev"
Requires-Dist: tifffile>=2023.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=2.0; extra == "docs"
Requires-Dist: myst-parser>=2.0; extra == "docs"
Requires-Dist: sphinxcontrib-mermaid>=1.0; extra == "docs"
Requires-Dist: sphinx-copybutton>=0.5.0; extra == "docs"
Dynamic: license-file

# SegSpy

[![CI](https://github.com/VANvonZHANG/SegSpy/actions/workflows/ci.yml/badge.svg)](https://github.com/VANvonZHANG/SegSpy/actions/workflows/ci.yml)
[![Lint](https://github.com/VANvonZHANG/SegSpy/actions/workflows/lint.yml/badge.svg)](https://github.com/VANvonZHANG/SegSpy/actions/workflows/lint.yml)
[![Docs](https://github.com/VANvonZHANG/SegSpy/actions/workflows/docs.yml/badge.svg)](https://vanvonzhang.github.io/SegSpy/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/VANvonZHANG/SegSpy/blob/main/LICENSE)

📖 **[Read the documentation](https://vanvonzhang.github.io/SegSpy/)**

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

```bash
pip install SegSpy
```

For the SAM backend, install the optional extra:

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

For development:

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

## Quick start

```python
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

```bash
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](CHANGELOG.md) for details. Contributions welcome — see
[CONTRIBUTING.md](CONTRIBUTING.md).
