Using metadata to adjust cell detection threshold

Hi Qupath Users,
I am doing a cell detection but my slides have variable intensity of hematoxylin. I have noted a threshold value called “T” for cell detection in the metadata of each image. I would like to use that value, add 0.035 to the value then use that as the threshold for a cell detection. Sorry I don’t know the syntax but the the script will be something like:

x double = getMetadata(T);
y double = 0.035;
z double = x+y;
runPlugin(‘qupath.imagej.detect.cells.WatershedCellDetection’…“threshold”: z, “maxBackground”: 2.0,…;

I’d really appreciate it if someone could help me write this correctly.
Thanks,
Alan

Hi @alk,

Is this what you mean?

// Get the value of 'T' from the entry's metadata (as double)
def t = getProjectEntry().getMetadataValue("T") as double

// Add 0.035 to it
def newT = t + 0.035

// Run the plugin with the new value
runPlugin('qupath.imagej.detect.cells.WatershedCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": ' + newT + ',  "maxBackground": 2.0,  "watershedPostProcess": true,  "cellExpansionMicrons": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true}');

yes thats brilliant! thank you very much!

2 Likes

Is it possible to write metadata from a script? For example assigning a metadata value T with a double

Yes, this is the line of code that you’re looking for:

getProjectEntry().putMetadataValue("Key", "Value")

And then you can read it like this (slightly more concise than the line from earlier post):

getProjectEntryMetadataValue("Key")

Note that values are always Strings, so you will need to cast them to double if you want to use them as such (e.g. def myValue = getProjectEntryMetadataValue("T") as double)

1 Like

Suberb, works a charm, thanks! I did incorrectly guess setMetadataValue…is there a resource/method I can use to find the correct syntax?

You can check out the official docs. They have a lot of different tips/methods to help you with your scripting :slight_smile:

Additionally, you can check out QP and QPex which have all the convenient methods that are automatically imported with all scripts (if Include default imports is ticked). Note that these might be subject to change in the next versions of QuPath!