Get class list and colors in QuPath tab

Hi all,

I’m trying to import cell classification results into QuPath. Cells will be visualized in different colors. Is it possible to get the class text and corresponding colors from QuPath tab? Looking forward to your reply.

Would you happen to know which version of QuPath you are using?
There are a bunch of scripts here showing color usage.
https://gist.github.com/Svidro/e00021dff92ea1173e535008854be72e
Some of which are by class.

Thanks for your timely reply. I’m using QuPath 0.2.0-m8.
I tried the code in the link you provided, but seems there is no fragments I need.

Sorry, I thought you wanted to access the text or colors of the classes. If you want to create a new class with new colors you can access the menu by right clicking in the class section of the tab, or alter a class color by double clicking on the particular class you want to alter. Other than that, I don’t think I understand what you are asking.

Yes, I’m trying to use some groovy code to access the text and colors of the classes.

Right, so the class is actually just the name of the class. So Stroma is “Stroma” as shown in the code. It also shows how to change the color to some RGB value.

For example, the following useless bit of code changes the stroma color to the tumor color, so that now the tumor and stroma are the same color.

stroma = getPathClass('Stroma')
tumor = getPathClass('Tumor')
print stroma.getColor()
stroma.setColor(tumor.getColor())

Thank you for kindly help. I think I’ve get the answer.
Use getQuPath().availablePathClasses to get all the available PathClasses
and for each class, we can use getColor() method to get the colors.

def all_classes = QPEx.getQuPath().availablePathClasses
stroma = getPathClass(all_classes[0])
1 Like