Cellpose is a generalised cell segmentation model available as an alternative to the default Mesmer segmentation in this pipeline. It supports nuclear-only segmentation as well as two-channel segmentation using a nuclear marker alongside a membrane or cytoplasmic stain.
To run Cellpose instead of Mesmer, set the --segmentation parameter:
--segmentation cellposeImportant
Cellpose is not supported with the conda or mamba profiles. You must use a container-based profile (Docker, Singularity, Apptainer, Podman, etc.).
--cellpose_model(string, default: bundledcyto3): Path to a pretrained Cellpose model.
By default, the pipeline uses the cyto3 model bundled with the container, which is a robust general-purpose cytoplasm model suited to most nuclear stains. To use a custom or fine-tuned model, provide the path to the model file:
--cellpose_model /path/to/my_custom_modelCustom models can be trained via the Cellpose GUI or Python API and then passed directly to the pipeline this way.
Included with this pipeline is a python script which will launch a re-segmentation GUI through napari. This script is designed to recognise the outputs of the pipeline, and provide an easy, relatively bug-free method to specify cell borders. Expand the topic below for a full tutorial on the use of this tool:
Using the resegmentation script
Installation
This resegmentation tool should take roughly 5-10 minutes to install. As a prerequisite, please install Miniconda or Anaconda if you don't already have it. After installation, restart your terminal (or computer on Windows) to ensure conda is available.
- Download or copy
run_reseg.pyandenvironment.ymlfrom the repository, or navigate there if you have cloned the repository. - Open a terminal in the directory containing these files.
- Create the conda environment:
conda env create -f environment.yml- Wait for installation to complete (~5-10 minutes).
Tip: You only need to create the environment once. For subsequent runs, just activate the environment and run the script.
Running the Program
-
Activate the environment:
conda activate cellpose_reseg
-
Run the script:
python run_reseg.py
-
When prompted, select your pipeline results directory (the folder containing
image_downscale/,segmentation/, etc.). -
After loading your images, the tool will open a napari viewer window similar to the one pictured below:
Tip You can hide/show layers, including all markers in your image, at the bottom-left-hand corner of the UI.
- Find areas where the segmentation is unsatisfactory, and click the "Add Patch at View Center" button to make a retraining patch. (you can change the size of this patch with the buttons above)
- Select the Segmentation (Corrections) layer, and paint in your new cells with the paintbrush button (press
+or=to advance the labels between cells) inside each of your patches.
-
Save your patches with the "Save All Patches (Cellpose Format)" button.
-
Select your model (you can link to
mihcro/bin/cyto3to avoid downloading the default model), and then click "Retrain Cellpose Model" to retrain your model. -
You can find your newly trained model in the results folder under
patches/models/, and use it in subsequent mihcro runs with--cellpose_model /path/to/results/patches/models/{model}
--cellpose_diam(integer, default:15): Expected cell diameter in pixels.
This is one of the most important parameters to tune for your data. It tells Cellpose the approximate size of the objects to segment, and has a large impact on segmentation quality. If left unset, Cellpose will attempt to estimate the diameter automatically, though this is less reliable than providing a value derived from your data.
Tip
A quick way to estimate the right diameter is to open your DAPI image in the Cellpose GUI, run the diameter estimation tool, and note the value it returns. You can then use that value here.
The appropriate diameter will depend on both the cell type and the image resolution. If your pipeline is run with --downscale_mode 1um (the default), the image will be at 1 µm/pixel, so --cellpose_diam corresponds approximately to cell diameter in microns.
--membrane_channel(string): Name of the membrane or cytoplasmic marker channel to use alongside the nuclear channel.
When specified, the pipeline runs a preprocessing step that stacks the membrane and nuclear channels into a two-channel image, which is then passed to Cellpose for whole-cell segmentation. See Two-channel segmentation for details.
Any additional Cellpose CLI arguments can be passed through to the process via task.ext.args in your Nextflow config. For example, to enable flow threshold adjustment:
process {
withName: 'CELLPOSE' {
ext.args = '--flow_threshold 0.8 --cellprob_threshold -1'
}
}A full list of available Cellpose CLI arguments can be found in the Cellpose documentation.
When --membrane_channel is specified, the pipeline runs a preprocessing step (PREPROCESS_CELLPOSE) prior to segmentation. This step stacks the membrane and nuclear channel images into a two-channel TIFF in the order [membrane, nuclear], which is then passed to Cellpose with the following channel configuration:
- Channel 0 (
--chan 0): membrane channel — the primary channel Cellpose segments around - Channel 1 (
--chan2 1): nuclear channel — used as a localisation guide for cell centres
This approach tends to produce more accurate whole-cell boundaries compared to nuclear-only segmentation, particularly in tissues with dense or overlapping cells. It requires that a suitable membrane or cytoplasmic marker (e.g. pan-cytokeratin, CD45, E-cadherin) is present in your panel.
To enable two-channel segmentation, set both --segmentation and --membrane_channel:
--segmentation cellpose \
--membrane_channel 'PanCK'The channel name must match exactly what is listed in your markerfile.
- Conda is not supported. The Cellpose module requires a container profile. Attempting to run with
condaormambawill produce an error. - Model bundling. The
cyto3model is bundled inside the container rather than downloaded at runtime, which improves reproducibility and avoids network dependency during execution. - Thread control. The process sets
OMP_NUM_THREADSandMKL_NUM_THREADSto match the number of CPUs allocated to the task, which can be tuned via your resource configuration if needed. - GPU acceleration. The default container does not enable GPU support. If GPU acceleration is required, a custom container with CUDA support would need to be specified via
task.ext.containeror an equivalent config override.


