Cell detection

From ClawBio/ClawBio · View interactive version

Cell detection is an AI agent skill from the GitHub repository ClawBio/ClawBio. 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.

How to use this skill

Skill file

🔬 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.

Core Capabilities

  1. Segment: Run cpsam on TIFF, CZI, ND2, PNG, or JPG fluorescence images
  2. Measure: Extract area, equivalent diameter, centroid, and eccentricity per cell
  3. Report: Produce report.md, {stem}_measurements.csv, and histogram figures
  4. Execution control: GPU auto by default, with explicit --use_gpu / --use_cpu override flags

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 |

| Zeiss microscopy | .czi | Reads CZI via czifile and uses CZI axis metadata (CziFile.axes) to map C/Z/Y/X deterministically |

| Nikon microscopy | .nd2 | Reads ND2 via nd2 and uses ND2 named dimensions (ND2File.sizes) for deterministic C/Z/Y/X mapping |

| PNG / JPEG | .png, .jpg, .jpeg | Greyscale or RGB |

Channel handling: cpsam is channel-order invariant for 2D inputs — cytoplasm and nuclear channels can be in any order. For 2D segmentation, if you have more than 3 channels, the first 3 are used and the rest are truncated with a warning. For 3D segmentation (--do_3D) with --z_projection none, 4D stacks are preserved as Z×C×Y×X (no channel truncation at load time).

Workflow

  1. Load image; detect greyscale vs multi-channel
  2. Prepare
  1. Segment with CellposeModel()
  1. Metrics via skimage.measure.regionprops
  2. Figures — overlay + size distribution histogram
  3. 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

# Override 4D stack Z handling (default is max projection)
python skills/cell-detection/cell_detection.py \
  --input <image.nd2> --z_projection none --do_3D --output <report_dir>

# Force CPU mode
python skills/cell-detection/cell_detection.py \
  --input <image.tif> --use_cpu --output <report_dir>

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

  1. Load image with tifffile (TIFF), czifile (CZI), nd2 (ND2), or PIL (PNG/JPG); use CZI/ND2 metadata axes to assign C/Z/Y/X
  2. Channel preparation:
  1. Instantiate CellposeModel(gpu=<flag>)
  2. Call model.eval(img, diameter=<arg_or_None>)
  1. Extract per-cell stats from masks via skimage.measure.regionprops
  2. Save {stem}_measurements.csv, figures, report.md

Key parameters:

Notes

Example Queries

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

Safety

Integration with Bio Orchestrator

Trigger conditions:

Chaining partners:

Citations

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.