setCellIntensityClassifications for a certain class

It is possible to perform setCellIntensityClassifications in QuPath for a certain class?
Thx

Hi @bp314,

Just to clarify, you want to set cells as positive and negative only for detections belonging to a specific class?

For context, could you explain why you want that? It’s just not immediately clear to me. Is it because you want a different classification for different classes?

1 Like

Hello @bp314,

Assuming that @lmurphy is right, maybe something like this could work?

import qupath.lib.objects.PathObject;
import qupath.lib.objects.PathObjects;
import qupath.lib.objects.PathCellObject;
import java.util.stream.Collectors;

// Change measurementName & thresholds variables as you like
def measurementName = "Nucleus: Hematoxylin OD min";
def thresholds = [0.05, 0.2] as double[];
def hierarchy = getCurrentHierarchy();
def cls = PathCellObject.class;

// Define the name of the class to classify
def myClass = "Tumor";

Collection<PathObject> pathObjects = hierarchy.getObjects(null, cls);

// Filter the objects to only retain the ones classified as 'myClass'
pathObjects = pathObjects.stream()
            .filter{object -> (object.getPathClass() == null) || (object.getPathClass().toString().substring(0, myClass.size()).equals(myClass))}
            .collect(Collectors.toList());
            
setIntensityClassifications(pathObjects, measurementName, thresholds);
hierarchy.fireObjectClassificationsChangedEvent(cls, pathObjects);

print "Done!"

Though this assumes that you’ve ran the cell detection AND the detection classifier prior. This script will just change the ‘positive/negative’ (or 1+/2+/3+) classifications of the specific class (defined in myClass).

It seems to work for me, hopefully that will help you solve your problem! :slight_smile:

1 Like