How do I classify cells?#

What will I learn?

  • How to create training annotations for a classifier.

  • How to interactively train an object classifier.

  • How to save an object classifier

  • How to load a previously-saved object classifier

In “How do I view measurements?”, we learned how to view measurements in QuPath. Now we’re ready to use those measurements to classify cells.

We’ll again use OS-2.ndpi. To recap, this shows a tissue sample with different cell types, stained for Ki67 and the analysis question we want to answer is:

What percentage of tumour cells are positive for Ki67?

To make things faster, we’ll follow along with the same annotations and detections made in How do I view measurements?.

Classifying objects#

What to do

  1. Run Classify ‣ Object classification ‣ Train object classifier.

  2. Click Live update.

../../_images/1-object-classifier-window.jpg

Fig. 69 Object classifier window#

We can assign classes to our cells by training an object classifier.

Initially, our object classifier won’t do anything, because we haven’t provided it with examples to learn from.

Note

It’s important to create new training annotations within the large region containing all of your cells, and not to change the class of the large region annotation itself. Otherwise, the classifier will treat all of these cells as belonging to that class.

Creating training annotations#

To train an object classifier, we need to provide examples of objects in each class we want to identify. Here, we’re focusing on Tumor and Stroma cells, so we need to identify regions containing detected cells that belong to both of these classes.

Tip

It can be helpful to toggle detection visibility when creating annotations (D). This can make it easier to identify cells that are being misclassified.

What to do

  1. Select an annotation tool of your choice

  2. Create a small annotation containing only what you think are tumor cells (or only stromal cells).

  3. Assign a class to this annotation. There are (at least) four ways to do this:

    • Using the Annotation tab in the analysis pane, we can select an annotation class and click Set selected to set the currently selected object as belonging to this class.

    • Right-click on the annotation to bring up the context menu, and select Set classification ‣ Tumor.

    • Use Shift and right-click to bring up a wheel of colours, where each colour represents a class (corresponding to the same colours shown on the left). Clicking on one of these circles will set the class of the object.

    • Enable Auto set in the annotation tab and create an annotation. Any annotations created will automatically be assigned to the currently selected class.

  4. Repeat steps 1-3 until you think you have a representative sample of tumor and stromal cells. As you create training annotations, the object classifier predictions will update.

../../_images/3-create-anns-menu.jpg

Fig. 70 Classifying annotations with the context menu or the annotation pane#

../../_images/4-create-anns-circle.jpg

Fig. 71 Classifying annotations with the circle palette or the annotation pane#

When you are finished, you should be left with something like this:

../../_images/5-object-classifier.jpg

Fig. 72 Object classifier preview#

Using an object classifier#

Now that we have some example regions containing objects of each type, QuPath will train a classifier that looks at the cells’ features and classifies them based on our training annotations.

You can change the type of classifier used and the features used as input. One useful option is to restrict the classifier to use only measurements from a given channel; for example, you might only use the DAPI channel in a multiplexed image, or only the DAB channel in a colour deconvolved RGB image.

Once you are happy with the classifier, you can save it, making it available for later recall and for scripting.

What to do

  1. In the Train object classifier window, enter a memorable name under Classifier name.

  2. Click Save.

  3. Save the image data (Control/Command+S); we will be using this image again.

  4. Close the object classifier window. Don’t worry, your objects are already classified!

The result of applying this classifier is that our cells are now classified as Tumor: Negative, Tumor: Positive etc. Now, we can finally answer our research question.

What to do

  1. Select the annotation that contains all of the detected cells.

  2. Ensure the analysis pane is open.

  3. In the Annotations tab of the analysis pane, you can see a summary of the number and proportion of Stroma and Tumor positive cells.

../../_images/6-multilevel-classes.jpg

Fig. 73 The annotation tab showing counts and proportions of tumor and stroma Ki67-positive cells#

Challenge: Loading an object classifier#

Challenge

  1. Create a new annotation containing cells.

  2. Run positive cell detection using the same settings as before (hint: workflows!).

  3. Load the object classifier you just saved (hint: Classify ‣ Object classification ‣ Load object classifier…).

  4. Apply the object classifier to classify your newly detected positive and negative cells as tumor or stroma.

  5. Did the classifier work correctly? Are there any issues with the output? Did you miss out any steps?

  6. Look at the Tumor: Positive % for this new annotation. How does this compare to the other annotation?