Created
October 7, 2024 09:16
-
-
Save romainGuiet/2701aedae64b2c6c13f3a9bad2e8bbc6 to your computer and use it in GitHub Desktop.
A QuPath script to make cell objects from lists of cytos and nuclei
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cytos = getDetectionObjects().findAll{it.getPathClass() == getPathClass('cells')} | |
nuclei = getDetectionObjects().findAll{it.getPathClass() == getPathClass('nuclei')} | |
print cytos | |
print nuclei | |
// Combine cytos and nuclei detections to create cell objects | |
def cells = cytos.collect{ cyto -> | |
cell_nucs = nuclei.findAll{ nuc -> cyto.getROI().contains( nuc.getROI().getCentroidX() , nuc.getROI().getCentroidY() )} | |
if ( !cell_nucs.isEmpty() ) { | |
// it happens that a cell contains more than one nuclei // Don't ask why ;) | |
// we merge the nuclei in one object | |
nuc = PathObjectTools.mergeObjects(cell_nucs) | |
// create the cell | |
cell = PathObjects.createCellObject(cyto.getROI(), nuc.getROI(), getPathClass("Cellpose"), null ) | |
//and add the the nuclei count as measurement | |
cell.measurements["Nuclei : Count "] = cell_nucs.size() | |
return cell | |
} else { | |
//return null | |
} | |
}.findAll{it!=null} | |
clearDetections() | |
addObjects( cells ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment