Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save grenkoca/86d4782fc825f90c1cf34557c0d320a1 to your computer and use it in GitHub Desktop.

Select an option

Save grenkoca/86d4782fc825f90c1cf34557c0d320a1 to your computer and use it in GitHub Desktop.
Exports all cell measurements within selections to a csv file
import qupath.lib.gui.QuPathGUI
import qupath.lib.measurements.MeasurementList
import qupath.lib.scripting.QP
/**
* Exports detection results to excel file
*
* @Author Frank Bonini
* @Author Caleb Grenko (did admittedly little)
*/
print 'Running script'
print 'Inside \'Run\''
/*
CHANGE THIS FILEPATH BEFORE USING THIS SCRIPT.
*/
def imageName = QuPathGUI.getInstance().getImageData().getServerPath()
imageName = imageName.substring(imageName.lastIndexOf('\\') + 1, imageName.lastIndexOf('.'))
print("Image name: $imageName")
def path = "" + QuPathGUI.getInstance().getProjectExportDirectory(true) + "\\${imageName}.csv"
// saveAnnotationMeasurements(path)
print 'Results exported to ' + path
print 'SAVE THESE RESULTS! THEY WILL BE OVERWRITTEN DURING THE NEXT TIME THIS SCRIPT IS RUN.'
def Annotations = QuPathGUI.getInstance().getImageData().getHierarchy().getSelectionModel().getSelectedObjects()
print "Annotations has this many elements: " + Annotations.size()
def Measurements = new ArrayList<MeasurementList>()
/*
For each annotation in the list
*/
for(a in Annotations){
for(c in a.childObjects){
Measurements.add(c.getMeasurementList())
// print c.getMeasurementList()
}
}
def MeasurementNames = Measurements.get(0).getMeasurementNames()
def rawMeasurements = new ArrayList<String>()
rawMeasurements.add(MeasurementNames.toString())
//Go through each cell
for(m in Measurements){
def measurementString = ''
//Go through each value and format it correctly
for(n in MeasurementNames){
measurementString += (m.getMeasurementValue(n) + ', ')
}
rawMeasurements.add(measurementString)
}
//print rawMeasurements
File file = new File(path)
for(m in rawMeasurements){
file << (m + System.getProperty("line.separator"))
}
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment