cell-detection
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.
š¬ 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
cpsamon 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()ā nochannelsargument 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) orPIL(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>)ā nochannelsarg (cpsam is channel-order invariant) - Extract per-cell stats from
masksviaskimage.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:
Nonetriggers 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 modeltifffileā TIFF I/OPillowā PNG/JPG loadingnumpyā array opsmatplotlibā figuresscikit-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