Export Measuresment for Mutiple Images in One project

Hi,
I’m running a QuPath script for multiple images in a project. The last part of the script (see below) contains ‘saveDetectionMeasurements’ to export custom measurements as a .txt file. This works fine when calling the script for an individual file. However, when I use “Run -> Run for project” on several files, only fundamental measures are saved and none of my intensity features are saved. Any idea about what I’m doing wrong here? Many thanks!


def name = getProjectEntry().getImageName() + '.txt'

setImageType('BRIGHTFIELD_H_E');
setColorDeconvolutionStains('{"Name" : "H&E default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "Eosin", "Values 2" : "0.2159 0.8012 0.5581 ", "Background" : " 255 255 255 "}');

createSelectAllObject(true);

runPlugin('qupath.imagej.detect.cells.PositiveCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "backgroundRadius": 15.0,  "medianRadius": 0.0,  "sigma": 3.0,  "minArea": 10.0,  "maxArea": 1000.0,  "threshold": 0.1,  "maxBackground": 2.0,  "watershedPostProcess": true,  "cellExpansion": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true,  "thresholdCompartment": "Nucleus: Eosin OD mean",  "thresholdPositive1": 0.2,  "thresholdPositive2": 0.4,  "thresholdPositive3": 0.6000000000000001,  "singleThreshold": true}');
selectDetections();

runPlugin('qupath.lib.algorithms.IntensityFeaturesPlugin', '{"downsample": 1.0,  "region": "ROI",  "tileSizePixels": 200.0,  "colorOD": false,  "colorStain1": true,  "colorStain2": true,  "colorStain3": false,  "colorRed": false,  "colorGreen": false,  "colorBlue": false,  "colorHue": false,  "colorSaturation": false,  "colorBrightness": false,  "doMean": false,  "doStdDev": false,  "doMinMax": false,  "doMedian": false,  "doHaralick": true,  "haralickDistance": 1,  "haralickBins": 32}');
path1 = '/G:/'
 
mkdirs(path1)

path = buildFilePath(path1, name)
saveAnnotationMeasurements(path)
print 'Results exported to ' + path

But this code will work when I just select one image manually and run the code for that image.

Hi @teethdiao, the script contains saveAnnotationMeasurements, not saveDetectionMeasurements. Is that the problem?

2 Likes

Wow, you are correct! I am so careless.

No problem, glad it could be quickly resolved! :smiley:

Thanks again! I have another problem. Is there any code that can put images into viewer from image list in order so that I can use run-run directly instead of run for Projects when running script.

Thanks again! I have another problem. Is there any code that can put images into viewer from image list in order so that I can use run-run directly instead of run for Projects when running script.

Yes… but is it essential that they are in the viewer? That raises a lot of threading troubles and is generally much slower than if you can work with ImageData objects directly (from which you can access everything).

There’s some info about reading these from projects at https://qupath.readthedocs.io/en/latest/docs/scripting/overview.html#projects

That said, you can use something like

getCurrentViewer().setImageData(imageData)

But you might need to wrap that all up into

Platform.runLater {
   getCurrentViewer().setImageData(imageData)
}

because of the aforementioned threading issues.

In summary, pretty much anything should be possible via scripting - but I’m not sure what precisely is required, and without a good justification it might be more trouble than it is worth.

1 Like

By the way, @melvingelbard has added an Export measurements command to v0.2.0-m10 that enables exporting measurements for a project without scripting.

1 Like