Exporting Positive Cells Only in the Mask


I have a typical fluorescent multiplex image with channels for DAPI, CD45, CD4, CD8 and FoxP3. I have detected the regulatory T cells which are positive for three markers - CD45, CD4 and FoxP3. I can also see the positive cell counts in the Annotation pane.

Analysis goals

Once the positive cells are detected, I want to export the cell-polygons as mask.
I’m this code in M9. This is good for exporting all cells; but for my project I want to export the positive cells only.

Is there a way to export the positive (i.e. CD45+CD4+FoxP3+) cells only as mask?


I’m not familiar with groovy, so can’t modify the above code for my project, unfortunately. However, found this code where the classes are used. Not sure if I should do something like this:

In the first code snippet, notice that they are getting all detections.

for (detection in getDetectionObjects()) {

All it sounds like you want to do is specify which detection objects.

fox = getDetectionObjects().findAll{it.getPathClass() == getPathClass("FoxP3")}

If your cells have multiple classes, it gets more complicated since you need to pay attention to subclasses. Pete’s script at the end of this page covers breaking up the class name.

1 Like

The multiplexed tutorial that I wrote introduces some of the recent improvements in how QuPath can represent classifications. Pay attention especially to the button that shows how to populate the available classifications from the channels – there are now lots of tricks for working with classes that are accessed through the menu that pops up when pressing that button.

@manaser In your case, you can use the menu to set the available classes to match those of the objects in your image. Then you can select the classification(s) you want from that list, and choose Select objects by classification (from the same menu) to select them.

This command is also ‘scriptable’, meaning that if you run it once you can find the corresponding Groovy script via the Workflow tab. It should look something like this:

selectObjectsByClassification("CD45: CD4: FoxP3");

This gives you the way QuPath represents the classification, which can be the starting point for modifying your script as @Research_Associate suggests.

1 Like

It worked! Thanks so much @petebankhead @Research_Associate