Optimization of cell detection

2,190 views
Skip to first unread message

Carlos Moro

unread,
May 12, 2017, 11:20:53 AM5/12/17
to QuPath users
Hello, 

This post is a bit related to the previous ones on 2-plex immunoquantification.

When reviewing the numbers for (positive) cell detection using default parameters (Slide 1 and 2 rows 2-4) the number of detected cells are quite large compared to row 5 manual counting.
Manual counting is naturally error prone but it'd be great to aproximate it, as it's current standard e.g. in diagnostic pathology.

My question is, what would be the best approach for an "objective" configuration / estimation of parameters in command "Cell detection" in order to optimize it for the particularities of cell types
(e.g. it'd be different for small lymphocytes than epithelial cells)?

I tried to make some changes (Slide 3) for these cells by increasing "background radius" from 8 to 15, sigma from 1.5 to 3, and minimal area from 10 to 30. 
The resulting numbers (Slide 4) seem to be more  in agreement with manual counting, but I don't know if those were the correct parameters to change or I'm just overfitting to this particular image.

Could you recommend some blueprints to estimate such parameters (e.g. depending on cell /nucleus size, etc)?

Best wishes,
Carlos

cell_detection_1.pdf

micros...@gmail.com

unread,
May 12, 2017, 7:21:27 PM5/12/17
to QuPath users
I don't think there are going to be much in the way of set standards, I vary my use of the tools all over the place, using several sub-samples in order to get what looks to be the best detection of the cells I am interested in.

Very frequently I will decrease the maximum nuclear size in order to prevent overly large "cells" that are due to overlapping nuclei, and in crease the minimum size in order to remove cells that are only partially in the plane of the slice I am looking at.  I also frequently set the background radius to 0 (off), which often increases my cell detection (my cell detection problems have generally been false negatives rather than false positives).  I think I recall background radius being useful in combination with the Max Background Intensity (maybe these should have been put next to each other? Note that they are linked) when using "Optical Density Sum" for my nuclear detection, but I rarely use that setting anymore.

I will generally increase or decrease my sigma depending on the relative sizes of the nuclei (anywhere from 3 for the largest nuclei to 0.5 for the smallest), and if there is more than one tissue type in a section, run different cell detection methods on different parts of the sample.  Unfortunately, the use and impact of all of these varies greatly depending on your chosen deconvolution vectors, which seem to have the greatest impact (for me).

Attempting to analyze a 2D plane of a set of 3D objects is always going to be rough, even using the exact same procedure, fixation permeation and other factors can vary the staining greatly from one experiment or sample to the next, so I am not sure you need to worry about over-fitting.  You absolutely will need to change your numbers on a regular basis to get accurate data.

In regards to widely varying cell types, note that one approach may be to obtain two data files with very "tight" detection settings and then merging/summarizing the outputs in another program like R.  

That said, I'm relatively new to this!  Feel free to correct any of my assumptions :)  I suspect Pete will have a much more accurate and knowledgeable answer.  His Gitbook on image analysis has been quite useful!

micros...@gmail.com

unread,
May 12, 2017, 11:35:42 PM5/12/17
to QuPath users
Actually, I think the best question in the case of your results not matching the manual count, is which cells/types of cells did the automated Cell Detection pick up that the manual count did not?  Do you see any cells registered in it that you disagree with?

Pete

unread,
May 13, 2017, 7:59:41 AM5/13/17
to QuPath users
I find this very interesting, and really appreciate the detailed and systematic approach.

As mentioned on the other thread, I think manual counts may tend to underestimate (I would presume it is more likely to miss a cell than it is to add one that isn't there), while automatic methods could go either way depending upon how they are set up (low/high thresholds etc.).  So I think that getting more cells by automatic detection when compared to manual counts isn't too bad; although many more cells would be a bit concerning.  In the end, it comes down to checking what was/wasn't detected in the image, and looking for any systematic biases.

Anyway, the settings that were modified are the ones I would also choose to modify.

The background radius should be either larger than the radius of your largest cell, or this setting should be turned off (i.e. <= 0).  If it is set, then at a basic level QuPath looks around each cell to try to find a background value, and then subtracts this prior to detection; the truth is somewhat more complicated, since background values then propagate throughout the image to try to give a better estimate.  Sometimes this helps if there is problematic background staining, sometimes (e.g. with very large cells, or dense clusters) it doesn't because there is no sensible radius that works.

I think the default setting isn't good for your image; so I'd also either go with 0 or ~15.
(Note that the background values in this case are only for detection, not measurement.)

The sigma value controls how much Gaussian smoothing is applied (here's the relevant bit of the aforementioned GitBook).  Larger values tend to decrease the number of detected cells; they reduce the chances of breaking up one nucleus into multiple detections, at a cost of increasing the risk of blurring nuclei together.  Currently, QuPath doesn't do any substantial 'multiresolution' processing for cell detection, so I'm afraid it's a matter of trying to find a suitable balance for all nuclei.
Again, I agree that the default is probably too low for this image; I tried sigma = 2 when I was exploring it last time.

The median filter reduces texture slightly - thereby decreasing spurious peaks that might appear inside large nuclei.  If you increase this value, you may find that you can keep the sigma value a bit lower.

The max background intensity only really matters if you have a background radius > 0.  It then uses the background image as a sanity check.  This can be useful if there is a large dark artefact present, which might otherwise produce a lot of false cell detections.  But it tends to only matter in more extreme cases.

And of course the main threshold value is key in deciding when the staining is dark enough to be a potential nucleus.

When I looked at this again, I realised that the standard Cell detection command (as opposed to Positive cell detection) gives red outlines by default - which are hard to see.  It might help to go to Edit -> Preferences and change the Default annotation color (and optionally Detection line thickness).  This is the color that is applied in the absence of any classification, even for cells as well.

It might also help to use View -> Cell display -> Nuclei only to avoid being distracted by cell boundaries; this option (where relevant) is also available by right-clicking on the image. 

Pete

unread,
May 13, 2017, 9:03:15 AM5/13/17
to QuPath users
A few extras...

You may set the Requested pixel size to 0.25… this should apply the detection at a higher resolution image (albeit more slowly).

You could also script the application of different parameters, which might look something like this:

for (sigma in [1.0, 1.5, 2.0, 2.5, 3.0]) {
    selectAnnotations();
    runPlugin('qupath.imagej.detect.nuclei.WatershedCellDetection',
        sprintf('{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 15.0,  "medianRadiusMicrons": 1.0,  "sigmaMicrons": %f,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": 0.12,  "maxBackground": 2.0,  "watershedPostProcess": true,  "excludeDAB": false,  "cellExpansionMicrons": 2.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true}',
        sigma));
    printf("Sigma: %f, Detections: %d", [sigma, getDetectionObjects().size()])
}

Finally, note that within the ‘Points tool’ you can save the points (as a zip file), and then load them back in.  That way if you have a really good set of manual counts, you can visually compare them to see which cells agree/disagree.

If you do that and want to push it any further, the next step may be to take advantage of the (rather obscure) function getObjectsForLocation, and automatically match the manual counts with the detections... but I'll leave that for now.

Carlos Moro

unread,
May 15, 2017, 5:11:37 PM5/15/17
to QuPath users
Hello,

Here's the test for cell detection.

It seems manual assessment clearly underestimated cell counts  O:)

Slide 3 (sigma 1, radius 1) looks quite good. It diminishes probably excess cell counts from radius 0 (slide 2) while detecting nearly all cells. 
Increasing sigma (slides 4-7) shows increasing amount of not detected cells (mostly with small nucleus in the image).

I didn't get better results with lower pixel size...

What do you think?

Best wishes,
Carlos

test_cell_detection.pdf

micros...@gmail.com

unread,
May 16, 2017, 12:16:05 AM5/16/17
to QuPath users
Looks good, expected behavior, roughly.  Dropping the pixel size from 0.5 to 0.25 wouldn't usually get you very much, my previous comment was on the 2.0um pixels from the add intensity features, which is a decent chunk of the cell!  

Not that people would probably use it much, but one thing to keep an eye out for at very low cytoplasmic expansions is that when there is no measureable cytoplasm (~0 um expansion)  the objects created are not actually PathCellObjects.  The object type is just PathDetectionObject and can create odd behavior with some of the other tools.  Subcellular detections, for example, will not work on an object created with 0 radius expansion, nor will any script that loops through all "cells."
Reply all
Reply to author
Forward
0 new messages