Convert Annotation Tiles to Detection with new parameters

Hi all, I need a hand in writing a script for QuPath 0.2.3.
This is my situation:


I have a certain number of Annotation Tiles, in each Tile there are detections.
I would like to transform each Tiles into a detection in order to observe some new parameters in the Measurements Map.

This is the annotations table


This is the detections table

These are the parameters that I would like to calculate for each tile (they therefore refer to the detections contained in each tile. I have almost all the variables used in the formulas, the only variables that are still to be calculated are the Sums):
Tile Density /mm^2 (giĂ  presente);

Total VD=Num Detections/Area µm^2*1000000; (it’s already present in the annotation table, I would like to be able to see it also in the detection table once the tiles are converted to detections)

ibcVD=Num irregular big coopted/Area µm^2*1000000;

ibuVD=Num irregular big uncoopted/Area µm^2*1000000;

ibVD=ibcVD+ibuVD;

rbcVD= Num regular big coopted/Area µm^2*1000000;

rbuVD= Num regular big uncoopted/Area µm^2*1000000;

rbVD= rbcVD+rbuVD;

scVD=Num small coopted/Area µm^2*1000000;

suVD=Num small uncoopted/Area µm^2*1000000;

sVD=scVD+suVD;

ibcVA= Sum of “irregular big coopted” detections areas;

ibcVA percentage= ibcVA /Area µm^2*10000;

ibuVA= Sum of “irregular big uncoopted” detections areas;

ibuVA percentage=ibuVA /Area µm^2*10000;

ibVA=ibuVA+ibcVA;

ibVA percentage=ibVA /Area µm^2*10000;

rbcVA=Sum of “regular big coopted” detections areas;

rbcVA percentage=rbcVA /Area µm^2*10000;

rbuVA=Sum of “regular big uncoopted” detections areas;

rbuVA percentage=rbuVA /Area µm^2*10000;

rbVA=rbuVA+rbcVA;

rbVA percentage=rbVA/Area µm^2*10000;

bVA=rbVA+ibVA;

bVA percentage=bVA/Area µm^2*10000;

scVA=Sum of “small coopted” detections areas;

scVA percentage=scVA/Area µm^2*10000;

suVA=Sum of “small uncoopted” detections areas;

suVA percentage=suVA/Area µm^2*10000;

sVA=scVA+suVA;

sVA percentage=sVA/Area µm^2*10000;

Total VA=(sVA+bVA);

Total VA percentage=(sVA percentage+bVA percentage);

total VCO mean (mean of “VCO” parameter of all detection classes, so i think it’s…) = sum of VCO(of that tile)/Num Detections);

rbVCO mean=(sum of VCO of “regular big coopted” detections+ sum of VCO of “regular big uncoopted” detections)/(Num regular big coopted+Num regular big uncoopted);

ibVCO mean=(sum of VCO of “irregular big coopted” detections+ sum of VCO of “irregular big uncoopted” detections)/(Num irregular big coopted+Num irregular big uncoopted);

bVCO mean=(sum of VCO of “irregular big coopted” detections+sum of VCO of “irregular big uncoopted” detections+sum of VCO of “regular big uncoopted+sum of VCO of “regular big coopted)/(Num irregular big coopted+Num irregular big uncoopted+Num regular big uncoopted+Num regular big coopted);

sVCO mean=(sum of VCO of “small coopted” detections+ sum of VCO of “small uncoopted” detections)/(Num small coopted+Num small uncoopted);

rbVCO percentage=Num regular big coopted/( Num regular big coopted+ Num regular big uncoopted)*100;

ibVCO percentage=Num irregular big coopted/( Num irregular big coopted+ Num irregular big uncoopted)*100;

bVCO percentage=(Num irregular big coopted+Num regular big coopted)/( Num irregular big coopted+ Num irregular big uncoopted+ Num regular big coopted+ Num regular big uncoopted)*100;

sVCO percentage=Num small coopted/(Num small coopted+ Num small uncoopted)*100;

total VCO percentage=(Num irregular big coopted+Num regular big coopted+Num small coopted)/Num detections*100;

So, in summary, I would like to be able to see all these parameters for each Tile converted to detection.
Knowing more or less the functionality of the program, it is possible that the detections inside the tiles will be deleted once the Tiles are converted to detection, but this is not important (although it would be nice to keep seeing them).
I know I am asking for a big effort, but I have to finish the project by November and i can’t write the script :worried:

Not going to dig into object names or any other specific calculations, but making detections that are roughly the same as annotations can be done like this:


detections = []
getAnnotationObjects().each{
    detections << PathObjects.createDetectionObject(it.getROI(), it.getPathClass(), it.getMeasurementList())
}
addObjects(detections)

If you have already created the measurements in the annotation, those will be copied over.

2 Likes

that’s exactly what I wanted to do. Thank you so much, as usual. Hope someone with some free time can sort out the rest. Have a nice Sunday!