How do I count positive cells?#

What will I learn?

  • How to annotate tumour regions

  • How to detect cells (again)

    • How to inspect the results

    • How to adjust parameters

    • How to find the parameters you used earlier

  • How to classify cells as positive or negative

  • How to detect & classify in one step

OS-2.ndpi shows a tissue sample with different cell types, stained for Ki67 – a marker of cell proliferation. The positive cells are brown (stained with DAB), the negative cells are blue (stained with haematoxylin).

The question we want to answer is:

What percentage of tumour cells are positive for Ki67?

Cells divide, and it’s normal for some to be positive for Ki67. But understanding how quickly the tumour cells are dividing can help determine the most appropriate treatment for several types of cancers.

One approach we can take is to

  1. Draw an annotation that we think only contains tumour cells.

  2. Calculate the percentage of cells inside the annotation that are positive.

That’s what we’ll do in this chapter. The manual annotation is laborious, but it can be the best approach if you don’t have too many images and you want full control over defining what cells are counted.

Later, we’ll draw a bigger annotation that contains a mix of tumour and non-tumour cells. Then we’ll need to add an extra step to train QuPath to tell the difference.

Detail of Ki67 image

How to annotate tumour regions#

What to do

  1. Open OS-2.ndpi

    • Choose Brightfield H-DAB as the image type

  2. Draw an annotation around a small region containing tumour cells

We won’t be diagnosing or treating anyone based on these results: you don’t need to do this with pathologist-level accuracy. If you aren’t confident you can tell which are the tumour cells, aim to annotate cells that look distinctively bigger.

Aim to create a single annotation that surrounds at least 100 cells.

../../_images/3-ki67_tumour_annotation.jpg

Fig. 49 Annotation surrounding tumour cells#

Tip

I’d suggest using the polygon or brush tool. These can draw complex shapes and are easier to control than the wand.

How to detect cells#

You can use exactly the same method to detect cells in this image as in the previous image.

This works because the image type has been set to Brightfield H-DAB: the image type tells QuPath the kind of staining you have, and the cell detection uses this information.

What to do

  1. Open Analyze ‣ Cell detection ‣ Cell detection…

  2. Click Run to run the cell detection in your tumour annotation

../../_images/4-ki67_cell_detection.jpg

Fig. 50 Cell detection in Ki67 image#

The order matters!

You need to set the image type correctly before you open the Cell detection… dialog.

If you change the image type after opening the dialog, then the parameters won’t automatically update. You’ll need to close the dialog, then once more run Analyze ‣ Cell detection ‣ Cell detection….

How to inspect the results#

QuPath’s cell detection is designed to do a reasonable job on a lot of images – and the default parameters are often ok for brightfield images. Still, it might not do a great job on your images.

It’s important to inspect the results. You can toggle how the cells are displayed, to help get a feeling for how accurate the detection is.

What to do

  1. Pan and zoom in/out to see if the cell detection looks good to you

  2. Press the F key repeatedly to fill/unfill your cells

  3. Press the D key repeatedly to show/hide your cells (detections)

  4. Right-click on the image and explore the options in the Cells ‣ popup menu

../../_images/5-ki67_inspection.jpg

Fig. 51 Changing how cells are displayed to help check the results#

Question

Where in QuPath’s user interface can you see the number of cells inside your annotation?

How to adjust parameters#

The Cell detection dialog contains a lot of parameters. As we’ve seen, sometimes changing one parameter can make the results a lot better.

You can hover the mouse over each parameter to see a description. Deciphering these may require some background in image processing – but some are quite intuitive.

Choosing the detection image#

What to do

  1. Open View ‣ Brightness/Contrast ../../_images/CONTRAST.png

  2. Compare the Hematoxylin and Optical density sum channels

    • Select the Show grayscale checkbox so they are easier to compare

A common change to try when optimizing cell detection in brightfield images is to switch the ‘Detection image’:

  • Hematoxylin OD uses digital stain separation to try to focus only on the nuclear staining

  • Optical density sum uses staining intensity, regardless of colour

Question

Which channel do you think we should use for detecting nuclei?

Hint: Decide which channel shows both the positive and the negative cell nuclei clearly.

Neither option is inherently better. The one that works best will depend upon the staining, which is why both options exist. But by looking at the channels individually, you can make an educated guess which will be better for your images.

What to do

  1. Change the Detection image parameter from Hematoxylin OD to Optical density sum

  2. Press Run to detect the cells again

  3. Inspect the results - do they look better or worse?

../../_images/6-ki67_detection_h.jpg

Fig. 52 Cell detection using the haematoxylin (stain-separated) image#

../../_images/7-ki67_detection_od.jpg

Fig. 53 Cell detection using the optical density sum image#

Choosing the requested pixel size#

What to do

  1. Explore what happens when you change the the Requested pixel size parameter

    • Use values of 0.25, 0.5 (the default), 1.0 and 2.0

  2. Check how the requested pixel size affects the number of detected cells and the accuracy of their boundaries

Sometimes the best way to understand what a parameter does is to draw a small annotation and the experiment by setting it to different values.

Question

Which requested pixel size would you prefer to use?

How to find the parameters you used earlier#

What to do

  1. Click on the Workflow tab

  2. Click on some of the entries that say ‘Cell detection’

  3. Check the parameter values at the bottom of the side bar

  4. Double-click on the first entry that says ‘Cell detection’

If you’re changing parameters a lot, it’s easy to lose track of what you’ve done. Fortunately, the Workflow tab in QuPath contains a log.

This log doesn’t contain absolutely everything (e.g., it doesn’t log when you draw an annotation), but it does log when you press Run in the cell detection dialog.

You can click on rows of the workflow table to find the parameters used when you ran cell detection in the past. Double-clicking on an entry should launch the cell detection dialog, with parameters initialized to match the values that were set at the time.

../../_images/8-ki67_workflow.jpg

Fig. 54 Viewing the recorded workflow to see previous commands & their parameters#

How to classify cells as positive or negative#

Once we’re reasonably happy with detection, we can move on to distinguish between cells that are positive and negative.

QuPath can do that by assigning a classification to the cell (often called a class for short). Then it can automatically count the number of cells with each class.

We first want to create space where we expect these counts to appear.

What to do

  1. Click on the Annotations tab – you should be able to see ‘Num detections’ at the bottom

  2. Click and drag the separator to make sure there are some empty rows in the measurement table below ‘Num detections’

../../_images/9-ki67_table.jpg

Fig. 55 Measurement table for the selected annotation#

Now we can actually assign the classes.

What to do

  1. Run Classify ‣ Object classification ‣ Set cell intensity classifications…

  2. For ‘Measurement’, select Nucleus: DAB OD mean

  3. Check that new measurements appear, including ‘Positive %’ under Annotations

../../_images/10-ki67_classification.jpg

Fig. 56 Setting cell classes based on DAB stain values#

Ki67 is a nuclear marker and the staining is DAB – so we want to classify cells as positive or negative based on Nucleus: DAB OD mean.

Question

What measurement would you use for a marker located in the cytoplasm, not the nucleus?

Question

What percentage of cells are considered Ki67 positive in your annotation?

The initial results will use a threshold value to decide when the nucleus is ‘brown enough’ to be called positive. Depending upon staining, this value might not always be appropriate. The slider allows us to change the threshold.

What to do

  1. Adjust the slider for ‘Threshold 1+’

  2. See that the cells change colour and ‘Positive %’ also changes

  3. Click Apply when you’ve got a threshold that seems appropriate

../../_images/11-ki67_classification_low.jpg

Fig. 57 Ki67 cell classification with a low threshold#

../../_images/12-ki67_classification_high.jpg

Fig. 58 Ki67 cell classification with a high threshold#

Question

How does the percentage of positive cells change if the threshold is low or high?

Tip

For Ki67, we normally apply one threshold: a cell can be positive or negative.

For some biomarkers (e.g. oestrogen receptor), it’s common to apply multiple thresholds – often 3. This can distinguish between cells with weak, moderate and strong positive staining.

That’s why QuPath provides 3 sliders to set thresholds.

How to count cells in the annotation tab#

Now that you have detected some cells, you can find out what the proportion of positive cells is within the region you annotated.

What to do

  1. Ensure the analysis pane ../../_images/MEASURE.png is open (Shift+A).

  2. Click the Annotations tab within the analysis pane.

  3. Select the annotation you are interested in, either in the annotation list or by clicking it in the viewer.

  4. View the details of the annotation within the Measurements pane.

../../_images/13-annotation-measurements.png

Fig. 59 Annotation measurements pane#

How to detect & classify in one step#

Because finding the percentage of positive cells is such a common task, there’s a single command that combines these two steps into one.

What to do

  1. Create a new annotation containing only tumor cells.

  2. Open Analyze ‣ Cell detection ‣ Positive cell detection….

  3. Compare the options in the dialog to the other dialogs you have seen in this chapter.

  4. Click Run to run the positive cell detection in your tumour annotation.

../../_images/14-ki67_positive_detection.jpg

Fig. 60 Positive cell detection for Ki67#

Question

What percentage of cells are considered Ki67 positive in this new annotation? Is it higher or lower than the previous example?

How to compare cell counts across annotations#

What to do

  1. Use Measure ‣ Show annotation measurements.

  2. If you want to make it a bit more concise, deselect the toggle buttons Show object IDs and Show images.

  3. Click on the column head Positive % to sort by this column (you may also want to drag it to the left side of the table).

If you want to compare multiple annotations, it would get a bit tedious to click on one in the annotation panel, note down the number of detections, and then repeat these steps for every annotation.

Luckily, we can instead view a table summarizing multiple annotations.

../../_images/15-annotation-measurements-table.png

Fig. 61 Annotation measurements table#