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
Run .
Click Live update.
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
Select an annotation tool of your choice
Create a small annotation containing only what you think are tumor cells (or only stromal cells).
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 .
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.
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.
When you are finished, you should be left with something like this:
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
In the Train object classifier window, enter a memorable name under Classifier name.
Click Save.
Save the image data (Control/Command+S); we will be using this image again.
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
Select the annotation that contains all of the detected cells.
Ensure the analysis pane is open.
In the Annotations tab of the analysis pane, you can see a summary of the number and proportion of Stroma and Tumor positive cells.
Fig. 73 The annotation tab showing counts and proportions of tumor and stroma Ki67-positive cells#
Challenge: Loading an object classifier#
Challenge
Create a new annotation containing cells.
Run positive cell detection using the same settings as before (hint: workflows!).
Load the object classifier you just saved (hint: ).
Apply the object classifier to classify your newly detected positive and negative cells as tumor or stroma.
Did the classifier work correctly? Are there any issues with the output? Did you miss out any steps?
Look at the Tumor: Positive % for this new annotation. How does this compare to the other annotation?