| name | cell-segmentation |
| description | Run cell segmentation on fluorescence microscopy images using Cellpose. Generates masks and extracts per-cell measurements. |
Skill: Cell Segmentation with Cellpose
Context
This skill runs cell segmentation on fluorescence microscopy images using Cellpose. Use this when you have images of cells (phase contrast, DAPI, or membrane stain) and need to generate segmentation masks and extract per-cell measurements.
Inputs
- Image directory: Path to directory containing .tif images
- Channel configuration: Which channel contains nuclei, which contains cytoplasm (if applicable)
- Model: Cellpose model to use (default:
cyto3 for whole-cell, nuclei for nuclear-only)
- Diameter: Expected cell diameter in pixels (or
None for auto-detection)
- Output directory: Where to save masks and measurements
Procedure
Step 1 — Scan and validate images
- List all .tif files in the image directory
- Read the first image to determine dimensions, number of channels, bit depth
- Report: number of images, dimensions, channels detected
- If images are multi-channel, confirm channel assignment with user
Stop and ask if: no .tif files found, images have unexpected dimensions, channel assignment is unclear.
Step 2 — Run segmentation
- Initialize Cellpose model with specified model type
- For each image:
a. Load image
b. Run segmentation with specified parameters
c. Save mask as
{original_name}_mask.tif in output directory
- Report progress every 10 images
Step 3 — Quality control
- For each mask, compute:
- Number of detected cells
- Mean and median cell area (in pixels)
- Fraction of image area covered by cells
- Flag images where:
- Zero cells detected
- Mean cell area is >3 SD from the batch mean
- Cell count is >3 SD from the batch mean
- Save QC summary to
{output_dir}/segmentation_qc.csv
- Generate a QC montage: 3×3 grid showing representative images with mask overlays
Step 4 — Extract measurements
For each cell in each image, measure:
- Cell area (pixels and µm² if pixel size is available)
- Centroid coordinates (x, y)
- Mean intensity in each channel
- Integrated intensity in each channel
- Eccentricity (shape measure)
Save to {output_dir}/cell_measurements.csv with columns: image_id, cell_id, area_px, centroid_x, centroid_y, mean_intensity_ch1, ...
Step 5 — Summary
Report:
- Total images processed
- Total cells segmented
- Mean ± SD cells per image
- Any QC flags raised
- Output file locations
Failure modes
| Issue | What to do |
|---|
| Image can't be read | Skip, log the error, continue with remaining images |
| Cellpose GPU not available | Fall back to CPU, warn about slower processing |
| Zero cells in an image | Log as QC flag, include in report |
| Out of memory | Reduce batch size, process images one at a time |
Reference files
These are in the same directory as this skill — read them if needed:
default_params.json — default Cellpose parameters for common imaging setups (confocal, widefield, etc.)
channel_conventions.md — lab-standard channel ordering and naming by stain panel
Dependencies
from cellpose import models
import numpy as np
from skimage import io, measure
import pandas as pd