qupath / qupath

QuPath - Bioimage analysis & digital pathology
https://qupath.github.io
GNU General Public License v3.0
1.04k stars 278 forks source link

Tile Classification to Annotations isn't working when used within a script #704

Closed FlorianLaforets closed 3 years ago

FlorianLaforets commented 3 years ago

Hello,

I am unsure whether reporting this here is the proper way to bring this up but I seem to be having a very similar issue as the one previously brought up here: https://github.com/qupath/qupath/issues/359

My OS is Windows 10 and I am using the 0.2.3 version. This is the system info: Version: 0.2.3 Build time: 2020-09-11, 12:59 Latest commit tag: '43aad4ec'

Java version: 14.0.2 Java vendor: AdoptOpenJDK - https://adoptopenjdk.net/ Java home: C:\Users\lafore01\AppData\Local\QuPath-0.2.3\runtime

Operating system: Windows 10 - 10.0 Architecture: amd64

What I have done so far: on a brightfield image, I first create DoG superpixels, calculate the intensity features, then load an object classifier to separate them into two classes: tumour and adipose. Finally, I use the tile classification to annotation feature. While all this works well when done manually, the following script (obtained by using the workflow to script feature) produces the same problem described previously when it reaches the tile classification to annotation line. See attached screenshot.

selectAnnotations(); runPlugin('qupath.imagej.superpixels.DoGSuperpixelsPlugin', '{"downsampleFactor": 4.0, "sigmaMicrons": 10.0, "minThreshold": 10.0, "maxThreshold": 230.0, "noiseThreshold": 1.0}'); selectDetections(); runPlugin('qupath.lib.algorithms.IntensityFeaturesPlugin', '{"pixelSizeMicrons": 2.0, "region": "ROI", "tileSizeMicrons": 25.0, "colorOD": true, "colorStain1": true, "colorStain2": false, "colorStain3": true, "colorRed": false, "colorGreen": false, "colorBlue": false, "colorHue": false, "colorSaturation": false, "colorBrightness": false, "doMean": true, "doStdDev": true, "doMinMax": true, "doMedian": false, "doHaralick": false, "haralickDistance": 1, "haralickBins": 32}'); runObjectClassifier("TumAd_superpixel"); runPlugin('qupath.lib.plugins.objects.TileClassificationsToAnnotationsPlugin', '{"pathClass": "All classes", "deleteTiles": true, "clearAnnotations": false, "splitAnnotations": false}');

TileClasstoAnnotation

As you can see it does nothing but successfully: no annotations are created. This only happens when I run this feature as a script. Manually it works perfectly. I have tried running all the script except the last line. This works well: it produced superpixels classified into tumour and adipose. But when I want to merge those superpixels to obtain two annotations (tumour and adipose), the line below on its own produces the same results as when run within the whole script: no annotation created.

runPlugin('qupath.lib.plugins.objects.TileClassificationsToAnnotationsPlugin', '{"pathClass": "All classes", "deleteTiles": true, "clearAnnotations": false, "splitAnnotations": false}');

I understand that I am using a newer version than the one in use when this problem was first brought up. It is therefore likely this was fixed. So maybe it's just that I am doing something wrong, but I thought that is should probably reported, in case it's a bug.

Best,

Flo

petebankhead commented 3 years ago

I'm not sure, because I don't have the same images and classifier to test exactly, but you might need a

selectAnnotations();

before the last runPlugin. This won't appear in the automatically generated script if you selected annotations manually.

The best place for questions like this is https://forum.image.sc/tag/qupath GitHub issues is really intended only for bug reports that follow the template (which should appear when you try to create a new issue). More people are likely to see any questions on the forum and give feedback; if it turns out that it really is a bug then it can always be added here later and linked to the forum discussion.

FlorianLaforets commented 3 years ago

Hi Pete,

Thanks for your reply and sorry for posting in the wrong place! I was indeed wondering if it was a bug. Next time I'll post in the QuPath forum and only move to here if advised to do so!

You were right adding a

selectAnnotations();

did make this work. Unsure why though, as I thought superpixels were detections not annotations? I had tried with

selectDetections();

but was obviously unsuccessful.

Thanks for your help and sorry again for posting in the wrong place!

petebankhead commented 3 years ago

No problem, glad it's fixed! I'll close the issue.

Yes, sometimes it's not entirely clear even to me whether some commands require selecting annotations or detections. I don't recall exactly what I was thinking when I wrote it, but the idea may have been that it operates on the detections within specific annotations... i.e. not indiscriminately merging detections regardless of the annotations they are inside. This makes some sense if you have multiple pieces of tissue as different annotations and don't want a single disconnected region to be generated that spans across them.

The best way to find out what should be selected is to run the command without anything selected at all. The popup dialog should then only give you valid options (here, Annotations or Entire image).