Skip to content

Instantly share code, notes, and snippets.

@adyprat
Created February 24, 2023 17:14
Show Gist options
  • Save adyprat/b2703b4943854e4640eefcca8f00ba86 to your computer and use it in GitHub Desktop.
Save adyprat/b2703b4943854e4640eefcca8f00ba86 to your computer and use it in GitHub Desktop.
Set class from existing measurements in QuPath
import qupath.lib.scripting.QP
import qupath.lib.objects.classes.PathClass
def pathClasses = getQuPath().getAvailablePathClasses()
print(pathClasses)
for (def detection : QP.getDetectionObjects()) {
def measurementList = detection.getMeasurementList()
// if cluster ID is 1, the name will appear as c1
// Change prefix variable to set a diff prefix
def preFix = 'c'
newClassID = preFix+(measurementList.getMeasurementValue("Clusters") as int).toString()
def newClass = PathClassFactory.getPathClass(newClassID)
if (!pathClasses.contains(newClass)){
pathClasses.add(newClass)}
detection.setPathClass(newClass)
}
// Fire update event
QP.getCurrentHierarchy().fireHierarchyChangedEvent(this)
println("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment