How do I do batch processing?#

What will I learn?

  • How to use the InstanSeg extension to detect nuclei and cells

  • How to use the workflow editor to create a script

  • How to use batch processing to run a script for multiple images in a project

We rarely need to analyze just one image. Usually, we have multiple similar images that we we want to analyze in a similar way.

This chapter uses images from the Broad bioimage benchmarking challenge, available to download from GitHub or from the link provided in the setup guide.

What to do

  1. Unzip BBBC007_project.zip

  2. Drag the resulting folder onto QuPath to open the project.

Cell detection with InstanSeg#

At the start of the workshop we advised installing some extensions, one of which was InstanSeg (alongside the Deep Java Library extension).

What to do

  1. Run Extensions ‣ InstanSeg ‣ Run InstanSeg. The InstanSeg dialog will appear as shown below.

    ../../_images/instanseg.png

    Fig. 78 InstanSeg dialog#

  2. Select the model from the dropdown called fluorescence_nuclei_and_cells-0.1.0 and click the download button ../../_images/DOWNLOAD.png next to it.

  3. Select an annotation tool and create an annotation.

  4. Ensure that an annotation is selected (in yellow by default).

  5. Click Run in the InstanSeg window.

It may take longer to process than the standard QuPath cell detection method, but once complete should look like below.

../../_images/instanseg-results.png

Fig. 79 InstanSeg results#

Tip

You can create an annotation covering the entire image with Objects ‣ Annotations ‣ Create full image annotation or using Control/Command+Shift+A.

For large images, a whole image annotation may take a very long time to run! It’s often better to run analysis only on a subset of the image, perhaps by restricting to only relevant tissue regions first, as shown in How do I detect tissue?

There are many more options to explore in InstanSeg, such as:

  • Choosing a device (GPU if you have one), changing the number of threads or tile size — these may change how long it takes to process images.

  • Selecting the channels that InstanSeg uses, rather than just using all channels. This can reduce memory usage and processing time with very large images.

  • Whether to produce cells or nuclei as the output. This is limited by the model used (some models only segment nuclei). For more information on InstanSeg, please check out the readTheDocs.

What to do

  1. Experiment with the options in InstanSeg until you find a combination that you are happy with.

  2. Save the work you have done on this image via File ‣ Save, or the keyboard shortcut of Control/Command+S.

QuPath workflows#

The Workflow tab in the side bar is the workflow tab. This records each of the steps performed on the current image.

../../_images/workflow.png

Fig. 80 QuPath with the workflow pane open#

Often, the workflow history on an image isn’t a perfect step-by-step workflow. For example, some steps (like creating annotations) aren’t captured. Furthermore, it’s rare that everything works perfectly first time. It often takes a few “test runs” to identify the right settings and order of operations for a good analysis.

Thankfully, QuPath allows you to edit the workflow.

What to do

  1. Click Create workflow in the lower left corner. This will produce a very similar window to the workflow pane.

  2. Delete things that aren’t needed by clicking Remove selected items.

  3. Re-order the remaining steps until it represents a sensible order of operations.

../../_images/workflow-editor.png

Fig. 81 QuPath with the workflow pane open#

  1. Select Create script.

Congratulations, you have just created your first script!

After clicking Create script, the script editor will open showing a script:

../../_images/script-editor.png

Fig. 82 QuPath’s script editor#

Running a script for all images in a project#

Once you are happy with your script, you could now open a different image in the project and run it. This would be quicker and less error-prone than repeating it manually, but it would still be very time-consuming for projects containing many images.

Alternatively, QuPath’s script editor allows you to run a script for every image in a project.

What to do

  1. In the script editor, select Run ‣ Run for project. This will open a dialog allowing you to select which images should be processed.

  2. Click the double right arrow >> to move all images into the right Selected pane to run the script on every image in the current project.

../../_images/run-dialog-full.png

Fig. 83 The run dialog filled in#

Then, QuPath will open each image in the project, run through each step of the workflow, and save the resulting changes. This makes it very convenient to reproduce exact analysis steps on many images with no manual intervention.

../../_images/instanseg-running.png

Fig. 84 InstanSeg running for project#

What to do

  1. Open another image in the project. This should show the results of running InstanSeg cell detection on that image.

../../_images/other-image.png

Fig. 85 InstanSeg results on another image#

Tip

InstanSeg also has an available model for nucleus detection in brightfield images. Models for other types of objects (and other image types) may be coming soon, watch this space!