Pixel Classifier: Classification Based on Size or Dimensions (QuPath)


I’m trying to automate the detection and ideally the quantification of several lesions in whole slide images using QuPath. All of my slides are H&E stained.

I’ve been training pixel classifiers to detect these lesions but am running into some problems. Some of my lesions are the same color as other lesions and differ only by size / dimensions. I’ve attached an example image where I am trying to quantify steatosis (the white circles within the tissue that I have annotated in red). The problem is when I switch to higher resolution in the pixel classifier (very high or full), It is detected as background or other white areas such as empty vessels.

My question is if there is a way to limit the detection of lesions (classes) by size or dimensions for pixel classifiers? For example, lesion 1 must be less than 100 pixels in size, lesion 2 must be between 500-1000 pixels in size, or if there is a long lesion (ex. 10 x 500 pixels), classify it as lesion 3 only if the length:width ratio is around 10:500.

I don’t have much experience in image analysis so I apologize if this is a silly / naive question but any help or advice would be greatly appreciated!

The pixel classifier classifies pixels, so your best option is to create all of the objects as detections first (eliminating much too large or much to small objects during the Create Objects step), then Add shape measurments to add Area values (or circularity or other measurements that would be useful), and then use Area to classify the objects with an Object Classifier.

Pixel classifier:
Creating objects:
Shape features:
Object classifier:
At this point I would recommend creating several Object classifiers with increasing thresholds.
So your smallest objects would be class: Size 1, Your next largest would be Size 2, etc.
When you combined those into a Complex classifier, you would end up with the resulting objects being classified:
Size 1, Size 1:Size 2, etc.


It is a little bit odd, and there are other, probably easier ways to do this through scripting if you are interested, but that is at least one way to get what you want through the GUI.

If you stopped at the adding shape features script, you could also do something like this:
setIntensityClassifications(getDetectionObjects(), "Area µm^2", [10,20,100] as double[]);

Note that the thresholds are in square microns, not the pixels you mentioned.

Actually, if you want more complex classifiers (rereading your description) you will probably want an if/else based script using the measurements.

Those two scripts should give you an idea how to use measurements to classify your objects through a script. Though you will want getDetectionObjects() not cells.

Thank you so much for all of the information and suggestions! Hoping to have a productive week trying out these approaches.

1 Like