Install Cellpose and use it through QuPath

How to install Cellpose and to use it through QuPath.

Cellpose Qupath installation

To install cellpose and integrate it with Qupath we follow their tutorial here.

Miniconda installation

In order to follow this tutorial we need to install miniconda, a virtual environment manager. We can find the download link here.

When you install miniconda you have to add it to PATH by ticking the checkbox during the installation!

Once conda is installed you have access to its terminal shell, from which we will have to do all the following operations (again from the tutorial). Using the Windos search bar, search for Miniconda Powershell and press Enter.

Cellpose installation

  1. Create a new environment (the name cellpose-205 can be changed as you wish):
conda create -n cellpose-205 python=3.8
  1. Activate the environment so we can work in it:
conda activate cellpose-205
  1. Install cellpose inside the environment:
pip install cellpose==2.0.5
  1. Because the default pytorch (deep learning package) is not compatible with the GPU, uninstall it:
pip uninstall torch
  1. Then install a version that works!
pip install torch --extra-index-url

Qupath cellpose plugin installation

  • Go here and download the .jar file. For keeping things consistent download the “0.3.10” version.
  • Open Qupath
  • Drag and drop the .jar file onto the window of Qupath. This should install the integration plugin.

Set-up cellpose preferences

  • Go to Edit -> Preferences…
  • Click on the drop-down menu “Cellpose”
  • Add the directory to where the cellpose environment is. Usually it’s something like: user/.conda/envs/cellpose-205/python.exe. The directory has to point to a Python Executable!
  • Select Cellpose Version 2.0
  • Select Python Executable

Cellpose use in Qupath

  1. Create ROI of any shape around the area you want to use Cellpose on (choose a big rectangle around everything if you want to segment the whole image or choose a polygon to cut-out certain parts)
  2. Copy in the Script empty window the code from the original repository):
  3. You can save this script to disk or as part of the project for later use!
  4. Modify this script as needed. Here are some important parameters:
  • Change the channels param with the name of the channel with which you want to segment with
  • Change the TileSize param with a high number (> the image size in pixels) to prevent tiling of the image (might improve segmentation quality but if the image is too large GPU might not be big enough!)
  • Set the diameter param to the average size of the structure you want to segment. If you don’t define it, cellpose will try to estimate it but it will take more time.
  • Change the rest of the paraments according to cellpose documentation if the segmentation is not as good as you expect.
  1. To run Cellpose, select the annotation you made in (.1) and press “Run” on the script editor (or CTRL+R)
  2. Wait for Cellpose to finish: you cannot click on anything until you see “Done!