Created
February 24, 2023 17:14
-
-
Save adyprat/b2703b4943854e4640eefcca8f00ba86 to your computer and use it in GitHub Desktop.
Set class from existing measurements in QuPath
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
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