Convert detections to annotations in qupath

Hi all,

I am currently using the Stardist implementation in Qupath with my own trained model. I don’t use it for detecting cells but multicellular structures in the intestines. The segmentation works astonishingly well but I would now need to convert the “Objects” into “Annotations” because I want to segment and quantify the cells per Object. Is there a way to do this? Alternatively I could run Stardist in Fiji and import the ROIs into Qupath but I don’t know how to do this.

Thanks!

6 Likes

This looks great! Very interesting to see this use of StarDist.

Here’s a quick script to convert detections to annotations:

def detections = getDetectionObjects()
def newAnnotations = detections.collect {
    return PathObjects.createAnnotationObject(it.getROI(), it.getPathClass())
}
removeObjects(detections, true)
addObjects(newAnnotations)

This won’t bother to retain any hierarchical relationships (parent/child objects)… which is complicated by the fact detections and annotations behave differently in this regard. If you want to establish such relationships, you can use insertObjects instead of addObjects… although it might be a lot slower.

For more info, see Object hierarchy — QuPath 0.2.3 documentation

3 Likes

Hi Pete,

Thank you for the quick reply, that’s exactly what I need! :slight_smile: There is no further hierarchical separation necessary in this case, just the cellcount and classification per object.
I’m also amazed how powerful and versatile StarDist is. It seems to work on almost any kind of roundish objects.

There’s one more question I have related to StarDist: I followed your instructions for building Qupath from source to include tensorflow and be able to run StarDist. Unfortunately this version is not able to load mrxs-files. I can work on exported regions but in some cases i would like to load a whole slice. Is there a way to resolve this?

Many thanks for your help!
Thomas

Do the same files open in the ‘normal’ version of QuPath (i.e. the installer that you can download and run)?

If so, my guess is that the build isn’t able to load OpenSlide. You might see errors about this under View → Show log. To figure out what is going wrong, I’d need more info about your exact steps and what operating system you’re using (Windows, Linux, macOS).

Would you be willing to make this training set public? I work on Barrett’s Esophagus/Esophageal Adenocarcinoma tissue and am really interested in measuring the crypt phenotype this way.

Thanks!

Hi Pete,

Yes, the files do open in the normal QuPath version.
In the log file there is this message: “ERROR: Could not load OpenSlide native libraries” so you were absolutely right.
I’m installing on Windows and I’m following your description using Github Desktop and then Gradle.
https://qupath.readthedocs.io/en/latest/docs/reference/building.html
I repeated the process but the outcome is the same.

Hi Thomas, which version of Java are you using (i.e. AdoptOpenJDK 14 or something else)?

Any other information you can share could be useful, for example other messages that are output when you start QuPath, or if you changed the branch on GitHub.

Hi David,

I would be glad to share but the data are not mine so I would have to ask the scientist first. The question is also if the structures are similar enough that the prediction will work. Let’s see.

Best,
Thomas

1 Like

Hi Pete, I installed this version of JDK: OpenJDK14U-jdk_x64_windows_hotspot_14.0.2_12
When I load a project I created with the normal QuPath and try to open an image I get the following message. When I load an image directly it only opens in a low resolution. In Github I’m using the main branch.

I know it’s difficult to find out the problem from the distance but thank you for trying!

DataLoadFailure