Auto class assign by ROI name

Is there a way to change the class of ROIs according to the name of the ROI?
For example;
If ROI name “ROI1 Tumor”, class will be “Tumor 1”

I have 4 ROIs including stroma and tumor parts created by SLIC superpixel segmentation and I am trying to get distance data for various TIL subtypes, however when there is only one tumor class, I am not able to measure the distances for the ROI itself, it is accepting all 4 tumor ROI as one and give me only one data instead of 4.
I am trying to number the tumor classes per ROI to get the distance data properly.

Thanks!

ROIs aren’t generally a class of object, but one aspect of various object types. In QuPath terms, I am guessing you mean Annotations?

If so, something like this should be pretty close.


getAnnotationObjects().each{
    it.setPathClass(getPathClass(it.getName().toString()))
}

It is not precisely what you asked for, but it converts the name into the class.

1 Like

A more specific example for your case might be

getDetectionObjects().each{
    it.setPathClass(getPathClass(it.getName().toString().split()[1]))
}

Which should split the string into two parts, and then take the second part as the class name.

Oh wait, that wouldn’t quite do it. But what you want would involve RegEx… which is not a lot of fun. But should work. See:

Um, good luck :slight_smile: It might be easier to start the naming process over such that it is easier to create the class name!

1 Like

I know but I named them as ROI1 Tumor or ROI1 Stroma. Their class was either Stroma or Tumor.
I need Stroma1 to Stroma 4 and Tumor1 to Tumor4 as 8 different classes for 4 ROIs.

Your script would help, let me try it.

Thanks a lot!

This is exactly what I needed. I have distance to annotation data for each specific ROI now since I have the classes with ROI names.

Thanks a lot, you saved me from changing class names one by one for thousand images!