Edit classifier: change number of channel


I created in QuPath a classifier for slides with immunofluorescence stainings:
-channel 1: DAPI
-channel 3: NeuN

Now, I want to use the same classifier for slides with stainings:
-channel 1: DAPI
-channel 3: TUNEL
-channel 4: NeuN

So, I should want to edit the file of the classifier to change the number of channel 3 to number 4.

How can I do this?

Thanks so much in advance!

1 Like

If you are using the built in trained classifier from the Classify menu, you would need to reload/recreate your training objects, and then simply add the new measurement as a feature. You would then need to add your new class and retrain. Once the classifier is completed and saved, I do not think there is any way to directly edit it to add new classes/channels/etc. As far as I know, your only option is to reload the training objects (if you saved them) and continue the training.

If you did not have measurements for a third channel, I am not certain this will work at all.

But it is not the purpose to add new training objects.
I want that in the second staining the classifier ignores the TUNEL signal and uses the NeuN signal that is here in channel 4 instead of channel 3.

That would need a new set of training objects. If you are writing your own script for classification, that is a very easy change to make, but it wouldn’t make sense to do that for a trained classifier. The channel intensities are generally different and would require a different threshold (and therefor a different training set).

If you are using something likethe simple cell classifiers here, then all you need to do is change the labels and figure out what your new threshold is.As described here, there are many ways to classify, but trained classifiers aren’t very flexible when you are changing things.

No, it is not based on a script, but on training objects.
The staining and intensities are the same, so no other thresholds are needed. It is because an issue with the scanning that the channel is in a different number, but both slides are in fact the same.

Ah, then no, you could either consider writing a script (which is as flexible as you need it to be), or adjust the slide channels prior to importing them into QuPath.

At some point it might be possible to change channel names via BioFormats (if your slides use BioFormats), but even then I am not sure if the classifier would target channels by name or by number. Not sure what the most common desired behavior would be there.

Yes, I am using BioFormats to open my .czi files!
How can I change the channel numbers before importing them to QuPath?

(Or how can I adjust this with a script? (I have never used scripts before))

This isn’t supposed to be possible. You might be able to achieve what you want with a script that that below, but I really haven’t checked it carefully and it does some terrible, hack-y things.

I could get it to run in QuPath v0.2.0-m2 but not in v0.1.2. Either way, you should run the analysis and use the classifier within the same version of QuPath and not mix between versions. If the conversion works at all, it should be possible to load the classifier in v0.1.2 as well.

// Define input & output paths (for the existing classifier, and where to write the modified one)
def fileInput = getQuPath().getDialogHelper().promptForFile(null)
if (fileInput == null)

// Deserialize the classifier
fileInput.withObjectInputStream {
    classifier = it.readObject()

// Print the current measurements (this isn't meant to be public!)
print classifier.measurements

// Update them (somehow)
def measurementsAfter = classifier.measurements.collect {it.replace('Channel 3', 'Channel 4') }

// Replace the measurements
print classifier.measurements

// Serialize the updated classifier
def fileOutput = getQuPath().getDialogHelper().promptToSaveFile("Save classifier", fileInput.getParentFile(), null, "Classifier", ".qpclassifier")
if (fileOutput != null) {
    fileOutput.withObjectOutputStream {
1 Like

Yes, it works!!!
Thank you so much!!!

1 Like

New things to learn every day!