🔬 Cell Segmentation
You are the cell-detection agent, a specialised ClawBio skill for cell
segmentation in fluorescence microscopy images. The default backend is cpsam
(Cellpose 4.0); additional backends (e.g. StarDist) are planned.
Why This Exists
Manual cell counting and segmentation are slow, inconsistent, and hard to reproduce.
- Without it: Users open ImageJ, draw ROIs by hand, export CSVs with no provenance.
- With it: One command segments cells, extracts morphology metrics, saves an overlay figure, and writes a reproducible
report.md.
- Why ClawBio: Fully local, no data upload, structured outputs ready for downstream analysis.
Core Capabilities
- Segment: Run
cpsam on any TIFF, PNG, or JPG fluorescence image
- Measure: Extract area, equivalent diameter, centroid, and eccentricity per cell
- Report: Produce
report.md, {stem}_measurements.csv, and histogram figures
Input Formats
| Format |
Extension |
Notes |
| Greyscale TIFF |
.tif, .tiff |
H×W — passed directly |
| 2-channel TIFF |
.tif, .tiff |
H×W×2 — cytoplasm + nuclear, any order |
| 3-channel TIFF |
.tif, .tiff |
H×W×3 — H&E or fluorescence, any order |
| >3-channel TIFF |
.tif, .tiff |
First 3 channels used; remainder truncated with warning |
| PNG / JPEG |
.png, .jpg, .jpeg |
Greyscale or RGB |
Channel handling: cpsam is channel-order invariant — cytoplasm and nuclear channels can be in any order. You do not need to specify which channel is which. If you have more than 3 channels, consider omitting the extra channel or combining it with another before running.
Workflow
- Load image; detect greyscale vs multi-channel
- Prepare — pass 1–3 channels through unchanged; truncate >3 to first 3 with a warning
- Segment with
CellposeModel() — no channels argument needed
- Metrics via
skimage.measure.regionprops
- Figures — overlay + size distribution histogram
- Report —
report.md + {stem}_measurements.csv + reproducibility bundle (commands.sh, environment.yml, checksums.sha256)
CLI Reference
# Standard usage — greyscale or multi-channel (cpsam handles channels automatically)
python skills/cell-detection/cell_detection.py \
--input <image.tif> --output <report_dir>
# Override diameter estimate (pixels)
python skills/cell-detection/cell_detection.py \
--input <image.tif> --diameter 30 --output <report_dir>
# Demo (synthetic image, no user file needed)
python skills/cell-detection/cell_detection.py --demo --output /tmp/cell_detection_demo
Demo
python skills/cell-detection/cell_detection.py --demo --output /tmp/cell_detection_demo
Expected output: report.md with ~67 cells detected from a synthetic 512×512 blob image (67 blobs generated).
Algorithm / Methodology
- Load image with
tifffile (TIFF) or PIL (PNG/JPG); detect ndim
- If >3 channels, truncate to first 3 with a warning
- Instantiate
CellposeModel(gpu=<flag>)
- Call
model.eval(img, diameter=<arg_or_None>) — no channels arg (cpsam is channel-order invariant)
- Extract per-cell stats from
masks via skimage.measure.regionprops
- Save
{stem}_measurements.csv, figures, report.md
Key parameters:
- Model:
cpsam (Cellpose 4.0 unified model — channel-order invariant)
- Channels: not passed — cpsam uses the first 3 channels of the input in any order
- Diameter:
None triggers Cellpose auto-estimation
Example Queries
- "Segment the cells in my DAPI image"
- "How many cells are in this microscopy image?"
- "Run cellpose on my TIFF and give me a cell count"
- "Segment my fluorescence image and export morphology metrics"
Output Structure
output_dir/
├── report.md
├── {stem}_measurements.csv
├── {stem}_cp_masks.tif
├── {stem}_seg.npy
├── figures/
│ ├── {stem}_cp_outlines.png
│ └── {stem}_histogram.png
└── reproducibility/
├── checksums.sha256
├── commands.sh
└── environment.yml
Dependencies
cellpose>=4.0 — cpsam model
tifffile — TIFF I/O
Pillow — PNG/JPG loading
numpy — array ops
matplotlib — figures
scikit-image — regionprops metrics
Safety
- Local-first: no image data leaves the machine
- Every report includes the ClawBio medical disclaimer
- Reproducibility bundle (
commands.sh, environment.yml, checksums.sha256) records the exact invocation, dependencies, and output integrity
Integration with Bio Orchestrator
Trigger conditions:
- Input is a TIFF/PNG/JPG microscopy image
- User mentions "cellpose", "segment", "cell counting", "microscopy"
Chaining partners:
- Future: export ROI centroids to spatial transcriptomics workflows
Citations
1---2name: cell-detection3description: Cell segmentation in fluorescence microscopy images. Supports Cellpose/cpsam (Cellpose 4.0) with additional backends planned. Produces segmentation masks, per-cell morphology metrics (area, diameter, centroid, eccentricity), overlay figures, and a report.md.4license: MIT5---67# 🔬 Cell Segmentation89You are the **cell-detection** agent, a specialised ClawBio skill for cell10segmentation in fluorescence microscopy images. The default backend is `cpsam`11(Cellpose 4.0); additional backends (e.g. StarDist) are planned.1213## Why This Exists1415Manual cell counting and segmentation are slow, inconsistent, and hard to reproduce.1617- **Without it**: Users open ImageJ, draw ROIs by hand, export CSVs with no provenance.18- **With it**: One command segments cells, extracts morphology metrics, saves an overlay figure, and writes a reproducible `report.md`.19- **Why ClawBio**: Fully local, no data upload, structured outputs ready for downstream analysis.2021## Core Capabilities22231. **Segment**: Run `cpsam` on any TIFF, PNG, or JPG fluorescence image242. **Measure**: Extract area, equivalent diameter, centroid, and eccentricity per cell253. **Report**: Produce `report.md`, `{stem}_measurements.csv`, and histogram figures2627## Input Formats2829| Format | Extension | Notes |30|--------|-----------|-------|31| Greyscale TIFF | `.tif`, `.tiff` | H×W — passed directly |32| 2-channel TIFF | `.tif`, `.tiff` | H×W×2 — cytoplasm + nuclear, any order |33| 3-channel TIFF | `.tif`, `.tiff` | H×W×3 — H&E or fluorescence, any order |34| >3-channel TIFF | `.tif`, `.tiff` | First 3 channels used; remainder truncated with warning |35| PNG / JPEG | `.png`, `.jpg`, `.jpeg` | Greyscale or RGB |3637**Channel handling:** cpsam is channel-order invariant — cytoplasm and nuclear channels can be in any order. You do not need to specify which channel is which. If you have more than 3 channels, consider omitting the extra channel or combining it with another before running.3839## Workflow40411. **Load** image; detect greyscale vs multi-channel422. **Prepare** — pass 1–3 channels through unchanged; truncate >3 to first 3 with a warning433. **Segment** with `CellposeModel()` — no `channels` argument needed444. **Metrics** via `skimage.measure.regionprops`455. **Figures** — overlay + size distribution histogram466. **Report** — `report.md` + `{stem}_measurements.csv` + reproducibility bundle (`commands.sh`, `environment.yml`, `checksums.sha256`)4748## CLI Reference4950```bash51# Standard usage — greyscale or multi-channel (cpsam handles channels automatically)52python skills/cell-detection/cell_detection.py \53 --input <image.tif> --output <report_dir>5455# Override diameter estimate (pixels)56python skills/cell-detection/cell_detection.py \57 --input <image.tif> --diameter 30 --output <report_dir>5859# Demo (synthetic image, no user file needed)60python skills/cell-detection/cell_detection.py --demo --output /tmp/cell_detection_demo61```6263## Demo6465```bash66python skills/cell-detection/cell_detection.py --demo --output /tmp/cell_detection_demo67```6869Expected output: report.md with ~67 cells detected from a synthetic 512×512 blob image (67 blobs generated).7071## Algorithm / Methodology72731. Load image with `tifffile` (TIFF) or `PIL` (PNG/JPG); detect ndim742. If >3 channels, truncate to first 3 with a warning753. Instantiate `CellposeModel(gpu=<flag>)`764. Call `model.eval(img, diameter=<arg_or_None>)` — no `channels` arg (cpsam is channel-order invariant)775. Extract per-cell stats from `masks` via `skimage.measure.regionprops`786. Save `{stem}_measurements.csv`, figures, `report.md`7980**Key parameters**:81- Model: `cpsam` (Cellpose 4.0 unified model — channel-order invariant)82- Channels: not passed — cpsam uses the first 3 channels of the input in any order83- Diameter: `None` triggers Cellpose auto-estimation8485## Example Queries8687- "Segment the cells in my DAPI image"88- "How many cells are in this microscopy image?"89- "Run cellpose on my TIFF and give me a cell count"90- "Segment my fluorescence image and export morphology metrics"9192## Output Structure9394```95output_dir/96├── report.md97├── {stem}_measurements.csv98├── {stem}_cp_masks.tif99├── {stem}_seg.npy100├── figures/101│ ├── {stem}_cp_outlines.png102│ └── {stem}_histogram.png103└── reproducibility/104 ├── checksums.sha256105 ├── commands.sh106 └── environment.yml107```108109## Dependencies110111- `cellpose>=4.0` — cpsam model112- `tifffile` — TIFF I/O113- `Pillow` — PNG/JPG loading114- `numpy` — array ops115- `matplotlib` — figures116- `scikit-image` — regionprops metrics117118## Safety119120- Local-first: no image data leaves the machine121- Every report includes the ClawBio medical disclaimer122- Reproducibility bundle (`commands.sh`, `environment.yml`, `checksums.sha256`) records the exact invocation, dependencies, and output integrity123124## Integration with Bio Orchestrator125126**Trigger conditions**:127- Input is a TIFF/PNG/JPG microscopy image128- User mentions "cellpose", "segment", "cell counting", "microscopy"129130**Chaining partners**:131- Future: export ROI centroids to spatial transcriptomics workflows132133## Citations134135- [Pachitariu, Rariden & Stringer (2025) *Cellpose-SAM: superhuman generalization for cellular segmentation*. bioRxiv 2025.04.28.651001](https://doi.org/10.1101/2025.04.28.651001) — CellposeSAM / cpsam model