This post is for people who want another option for classification within QuPath, in addition to the machine learning classifiers, quick, single line classifier scripts (also covered in previous link), more complicated classifier scripts (my list here, here in detail from Pete with automatic thresholds, in many places on the old Google forum), or the built in single feature classifier (Classify menu).
Edit: Since it was buried in the text, I am also placing the link to the GUI cell classifier script here.
My variant creates a distinct class for every possible combination of base class types, which can help when running classifications on multiple images, some of which may not have a given cell type. Having some different numbers of columns per image can make lining up data export… tricky. In addition, while most basic classifiers can handle one or two colors easily, the total number of base classes starts to result in a very large number of possible combinations. 2^number of clases, in fact. At one class feature (say nuclear DAB intensity), you only have 2 classes, positive and negative. Throw in some red AP staining, and you have 2^2, or 4 classes (negative, brown nucleus, red cytoplasm, brown+red). Once you get to 6 base classes, that is 64 potential classes, which I don’t think anyone would want to deal with as far as training a machine learning classifier.
So if you are still interested, here we go! This will all be done on the Luca 8 channel image used in Pete’s examples from his blog, and is available here.
This is the base image, for reference.
As a mild segue, for a sample like this I often want separate regions of interest, and I use this script to generate annotations based on a particular channel. There is one line in the script (114) where getAvailableChannels() needs to be replaced with availableChannels() depending on which version of QuPath you are using. An error will let you know if you need to change it! Another error you might run into is that the downsample size needs to be high enough to send the entire image to ImageJ… meaning frequently 8-15 in whole slide samples. In the milestone release of QuPath, you should be able to use the pixel classifier to do something similar, and with greater precision.
I also like to use the brush tool to draw a small area to determine what values I should enter to remove small bits of annotation, or the size holes I want to fill in.
Which I use to get this:
And then merge the results and generate an inverse annotation to look at the remaining areas:
At this point, I perform my cell detection, and then run the classifier script that has a GUI. There is another version here where you can load a saved classifier without any UI, which enables you to run the classifier across an entire project as part of a script.
The first window in the upper right allows you to select how many base classes/features you are interested in using to create your classifier. This image has 6 channels of interest (plus DAPI and an empty [AF?] channel), so I will choose 6. Upon clicking Start Classifying, I get the second window in the upper left. The image shows me starting with the first channel (dropdown on the left) that I know by inspection to be a cytoplasmic marker; I open Measure->Measurement Maps (shown lower right) and adjust the right hand slider so that the cells I feel are positive are all shown in red. I then use that value as my lower threshold for positivity by adding it to the left “Lower Threshold” window. I normally do not use the Upper threshold window as it defaults to the maximum pixel value for your image, but it might allow you to eliminate some bright artifacts. Finally, I name the class and select a color from the dropdown on the right. I stroooooooongly recommend short class names, especially if you will have cells that are positive for 3 or more markers. The names get quite long.
After going through that process for all channels of interest, I name and save the classifier for later use, and click Run Classifier. Considering moving that button more to the center…
Excel output for the two annotations shown below… but those are just counts. I usually am more interested in percentages or densities. There is another script for that here, which will add percent positive and cells/mm^2 of each class to the parent annotation. Much easier than calculating things one at a time. Here are some of the “Tumor” annotation measurements.
Ok, so now there are potentially 64 classes, and this is all very hard to look at. Pete had some suggestions that definitely help with that in his post on classifying linked above, but I now have the added problem that… well, maybe my “C1c, C3n, C4c positive” cells are actually T-cells? This script helps both problems by allowing you to rename or recolor any class. In the following example I turned all of my tumor cells that were only C6c positive (Teal) black, so that any cells infiltrating the tumor would be emphasized. I also called them BadCells just because. As you can see in the image, the C6 cells no longer show up.
Another, more mature, way to handle this might be to add a class to my Annotations tab list of classes and toggle it off, as shown.
Apologies for how long this was, though I am sure I forgot some things along the way. So please do ask if you have any questions or anything could be clearer! Scripts were all run in QuPath 0.1.3, so some code alterations may be necessary for different versions, as mentioned.