napari plugin for cellpose (see - an anatomical segmentation tool

MouseLand, updated 🕥 2022-09-06 19:37:22

cellpose-napari cellpose

Documentation Status tests codecov PyPI version PyPI - Downloads Python version License Contributors website GitHub stars GitHub forks

a napari plugin for anatomical segmentation of general cellular images

This napari plugin was generated with Cookiecutter using with @napari's cookiecutter-napari-plugin template.

The plugin code was written by Carsen Stringer, and the cellpose code was written by Carsen Stringer and Marius Pachitariu. To learn about Cellpose, read the paper or watch this talk.

For support with the plugin, please open an issue. For support with cellpose, please open an issue on the cellpose repo.

If you use this plugin please cite the paper: ::

  title={Cellpose: a generalist algorithm for cellular segmentation},
  author={Stringer, Carsen and Wang, Tim and Michaelos, Michalis and Pachitariu, Marius},
  journal={Nature Methods},
  publisher={Nature Publishing Group}



Install an Anaconda distribution of Python -- Choose Python 3 and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path.

Install napari with pip: pip install napari[all]. Then install cellpose-napari via [pip]:

pip install cellpose-napari

Or install the plugin inside napari in the plugin window.

If install fails in your base environment, create a new environment: 1. Download the environment.yml file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. 2. Open an anaconda prompt / command prompt with conda for python 3 in the path 3. Change directories to where the environment.yml is and run conda env create -f environment.yml 4. To activate this new environment, run conda activate cellpose-napari 5. You should see (cellpose-napari) on the left side of the terminal line.

If you have issues with cellpose installation, see the cellpose docs for more details, and then if the suggestions fail, open an issue.

Upgrading software

You can upgrade the plugin with ~~~ pip install cellpose-napari --upgrade ~~~

and you can upgrade cellpose with ~~~ pip install cellpose --upgrade ~~~

GPU version (CUDA) on Windows or Linux

If you plan on running many images, you may want to install a GPU version of torch (if it isn't already installed).

Before installing the GPU version, remove the CPU version: ~~~ pip uninstall torch ~~~

Follow the instructions here to determine what version to install. The Anaconda install is recommended along with CUDA version 10.2. For instance this command will install the 10.2 version on Linux and Windows (note the torchvision and torchaudio commands are removed because cellpose doesn't require them):

~~~ conda install pytorch cudatoolkit=10.2 -c pytorch ~~~~

When upgrading GPU Cellpose in the future, you will want to ignore dependencies (to ensure that the pip version of torch does not install): ~~~ pip install --no-deps cellpose --upgrade ~~~

Installation of github version

Follow steps from above to install the dependencies. In the github repository, run pip install -e . and the github version will be installed. If you want to go back to the pip version of cellpose-napari, then say pip install cellpose-napari.

Running the software

Open napari with the cellpose-napari dock widget open napari -w cellpose-napari

There is sample data in the File menu, or get started with your own images!

Detailed usage documentation.


Contributions are very welcome. Tests are run with pytest.


Distributed under the terms of the BSD-3 license, "cellpose-napari" is free and open source software.


cellpose-napari relies on the following excellent packages (which are automatically installed with conda/pip if missing): - napari - magicgui

cellpose relies on the following excellent packages (which are automatically installed with conda/pip if missing): - torch - numpy (>=1.16.0) - numba - scipy - natsort - tifffile - opencv


cellpose-napari crashes when running segmentation on Mac

opened on 2023-01-25 11:34:44 by christinab12


I'm trying to run the cellpose-napari on MacOS v.11.7.2 with Intel Graphics and following versions:

cellpose==2.1.1 cellpose-naapri==0.1.5 napari==0.4.16 pyhton==3.9.13

As soon as I hit the "run segmentation" button I get ~/envs/napari/bin/pythonw: line 3: 7607 Segmentation fault: 11 ~/envs/napari/ "[email protected]"

Is this expected behaviour? Do I need to change my versions? I saw something similar on the closed issues, but that was more than a year ago, not sure what the latest is?

Thanks, Christina

Cell segmentation XYZ coordinates export

opened on 2022-11-28 16:05:21 by alfonsecard

Hi, thanks a lot for developing this software. I've been struggling with cell segmentation in 3D for a long time and your software is working so well after training the model with a few images.

I am able to obtain very accurate cell masks in 3D, but now I'm having problems converting this data into an XYZ coordinates text file (that I need for a subsequent smFISH-dot count analysis).

Do you have any recommendations on how I can obtain this?


`get_masks` interface changed from cellpose 1.x to 2.x

opened on 2022-10-26 18:53:22 by aeisenbarth

When clicking "recompute last masks with new cellprob + model match", I get the error: ``` File …/lib/python3.8/site-packages/cellpose_napari/, in widget_wrapper..compute_masks(masks_orig= (1000, 1000) uint16, flows_orig=[ (1560, 1560, 3) uint8, (2, 1560, 1560) float32, (1560, 1560) float32, (2, 1560, 1560) float32], cellprob_threshold=8.0, model_match_threshold=27.0) 114 logger.debug('flow_threshold=0 => no masks thrown out due to model mismatch') 115 logger.debug(f'computing masks with cellprob_threshold={cellprob_threshold}, flow_threshold={flow_threshold}') --> 116 maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold), flows_orig[3] = (2, 1560, 1560) float32 flows_orig[2] = (1560, 1560) float32 cellprob_threshold = 8.0 flows_orig = [ (1560, 1560, 3) uint8, (2, 1560, 1560) float32, (1560, 1560) float32, (2, 1560, 1560) float32] flow_threshold = 0.4 flows_orig[1] = (2, 1560, 1560) float32 masks_orig = (1000, 1000) uint16 117 flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3)) 118 maski = fill_holes_and_remove_small_masks(maski) 119 maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1], 120 interpolation=cv2.INTER_NEAREST)

TypeError: get_masks() got an unexpected keyword argument 'flows' ```

Environment: cellpose 1.0.2 cellpose-napari 0.1.5 napari 0.4.16 napari-plugin-engine 0.2.0

This is caused by the removal of the flows argument in the get_masks function in the transition from cellpose 1.x to 2.0. However, the requirements cellpose>=0.6.2 currently pull the latest package version. The current code would need to specify an upper limit cellpose>=0.6.2,<2, or be updated to the new interface.

Workaround: Install cellpose==1.0.2

Extend test timeouts (mostly for macOS)

opened on 2022-08-26 23:51:03 by psobolewskiPhD

The 3D segmentation test on macOS seems to be around 80 s pretty consistently, so easy to hiccup and hit over 90: Bumping the other one to 60s just to be safe.

Remove copy-pasta error

opened on 2022-08-26 20:10:29 by psobolewskiPhD

This line was a copy paste error: the rgb_3D sample is already cropped, with shape (2, 75, 75, 75), so this line does nothing.

CellPose Napari plugin does not consider scale of original layer

opened on 2022-08-22 17:52:51 by sebi06

Hi all,

I just tested the CellPose plugin in Napari and it seems the its output does not have the same scale a the original layer (to be segmented): For a detailed description check:


collaborative analysis of neural recordings

GitHub Repository Homepage

napari segmentation