Need help with troubleshooting distance to annotation calculation

Hello,
Using version v0.2.3, I am trying to calculate the distance of every detected cell to the annotation boundary (of class “Tumor”). I execute the following script for cell detection and distance measurement and it runs without any errors or warnings. However, for every cell the “Distance to annotation with Tumor” measurement turns out to be zero.

setImageType('BRIGHTFIELD_OTHER');
clearDetections();
selectAnnotations()

// Stain vectors adjusted to include purple chromogen
setColorDeconvolutionStains('{"Name" : "VIP chromogen", "Stain 1" : "Hematoxylin", "Values 1" : "0.663 0.677 0.32 ", "Stain 2" : "Purple", "Values 2" : "0.547 0.735 0.402  ", "Stain 3" : "DAB", "Values 3" : "0.468 0.615 0.634 ", "Background" : " 255 255 255 "}');

//Positive cell detection
runPlugin('qupath.imagej.detect.cells.PositiveCellDetection', '{"detectionImageBrightfield": "Optical density sum",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 25.0,  "maxAreaMicrons": 400.0,  "threshold": 0.1,  "maxBackground": 10.0,  "watershedPostProcess": true,  "cellExpansionMicrons": 3.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true,  "thresholdCompartment": "Nucleus: Purple OD mean",  "thresholdPositive1": 0.32,  "thresholdPositive2": 0.4,  "thresholdPositive3": 0.6000000000000001,  "singleThreshold": true}');

//selectObjectsByClassification("Tumor")
detectionToAnnotationDistances(true)

Am I doing something wrong here? Do I need to call another function/method before calling detectionToAnnotationDistance(true)?

I also tried to modify and run the newer script for calculating the cell distance to annotations for TMAs and I get the same result.

I am guessing its something very trivial… but can’t figure it out.

Any suggestions is greatly appreciated.

1 Like

The distance is to the outside, so at the moment you would need to select and invert the Tumor in order to get a distance. Or script the distance transform more manually.

*I have grown more and more fond of having negative distances inside of objects as time has gone on…

Ah ok… Got it…

Thanks!

1 Like

Something like this might help streamline the process… though it will depend on your tumor region layout. If it is complicated, I would mergeSelectedAnnotations() after selecting them, then select and split them again after.

In total:

selectObjectsByClassification("Tumor");
mergeSelectedAnnotations()
makeInverseAnnotation()
getSelectedObjects().each{it.setPathClass(getPathClass("TumorBorder"))}
detectionToAnnotationDistances(true)
clearSelectedObjects(true)
selectObjectsByClassification("Tumor");
runPlugin('qupath.lib.plugins.objects.SplitAnnotationsPlugin', '{}');

*Uncertain how this will interact with TMAs… there might be some weirdness there.

My samples are not TMAs… but tumor tissue with numerous “Necrosis” and “Tumor” regions. For convenience, I have deleted all the “Necrosis” regions. I will give it a try and let you know how this works.

Thanks for the super fast reply (As always!).

1 Like