Classifying cell detections using tiles

Hello everyone,

Is there a way to classify detected cells using overlapping tiles that have been classified?

As you can see in the picture below, I have my cell detections superimposed over my classified tiles, and I’d like the cells to adopt the classification of the tile they coincide with:

Put differently, I’d like to do something similar to the “classify” button when you load a pixel classifier, but I have a superpixel-trained object classifier… Any way to do this?

Thanks :slight_smile:

Are your tiles still detections? I.e. have you merged them into annotations yet? It looks like you have not but I wanted to be sure.

No I haven’t… they’re still detections and therein lies the problem… I guess this is kinda embarrassing but forgot that you can turn detections into annotations… is it that easy?

SLICs can be done through a command in the menu Tile Classifications to Annotations - like following this guide.

On the other hand it sounds like you could use something like this:

SLICs = getDetectionObjects().findAll{it.isTile()}
SLICs.each{tile->
    cellsInTile = getCurrentHierarchy().getObjectsForROI(qupath.lib.objects.PathDetectionObject, tile.getROI())
    cellsInTile.each{cell->
        cell.setPathClass(tile.getPathClass())
    }
}
fireHierarchyUpdate()

As always save your data first.

2 Likes

Worked like a charm, thanks as always :slight_smile:

1 Like

Okay, so, new problem:
Tiles to annotations works exactly like I need it to, but if you may recall from an older post I’ve made, my goal with this project is to split the biopsy into Necrotic, At-Risk, and Healthy zones. For some reason, the Tiles to annotation gets rid of the annotations even when I have the “delete existing annotations” box unchecked. Furthermore, I can’t get around this by redrawing them after as the brush tool causes the new annotation I’m drawing to incorporate into the ones that are already there. Am I missing something or am I at a standstill here?

You may need to store and recreate the annotations - but if you only needed to classify cells it would not be a problem, just delete all of the tiles when you are done using them.

If you need the annotations (which can be incredibly messy, as I am sure you have seen - some smoothing can help here), you need something like

originalAnnotations = getAnnotationObjects()
//the script stuff that ends up getting rid of the annotations - convert tiles to annotations or whatever
addObjects(originalAnnotations)
1 Like

Well, this is what I get for being lazy… I hadn’t tried the code you linked to define the cells based on the tiles. That circumvents the issue lol. Thank you <3

1 Like