Default color for exporting training regions

Hi, I’ve been trying to comb through the source code to see if I could figure this out on my own, but I’m far from sure, so I’ll ask here instead:

In Qupath-0.2.0-m2, there is a new feature under Extensions -> AI -> Export training regions which makes it easier to create full image annotations for training neural networks to do segmentation tasks. This new menu option opens a dialog, where the user inputs a list of class labels in the format “class name: int”. My main question is, if an image is only partially annotated before starting the export, what color will then be used for the unannotated regions? Is it always black or is it always the first class in the list? maybe it is always the class with the lowest number or the class named Background? I can’t seem to figure it out. Nor can I figure out why each class label needs to have an associated integer.

From recollection, the integer is the value of the pixel in the output image. It is an 8-bit indexed color image. If you end up reading it elsewhere and getting instead an RGB image, then that happened during the image reading stage… not the export stage.

The integers are then the actual pixel values that were exported. Unannotated regions should have the label 0.

1 Like

Ah yes, it appears you are right. Index 0 is then unannotated and index 1 is the first label. Would it then be a simple matter to add an option to change the index and color for unannotated, such that it could be like the VOC dataset, where index 255 is white and used as an ignore label?

It should be outside of QuPath :slight_smile:
Although from a quick look at the code, it appears that I added support for that although I haven’t used it in a long time. Try just 255 on its own line (not with an associated label) through the GUI where you’d normally enter the integer label.

That didn’t work, but it did inspire me to modify an older script to do what I was looking for, so that’s nice :slight_smile:
Right now, the export option defaults to black if annotations are missing, so I guess you could easily change this behavior down the line, when you finish with more pressing matters.

I’ve just tried it and for me it works. I used

Tumor: 1
Stroma: 2

I’m not convinced that 255 is a better default than 0 in general…

Ah, okay, I didn’t try it as the first line, so that might be the difference. The reason for using 255, though, is that usually black is reserved for the background label, while white is reserved for the “ignore” or “don’t care” label and I believe that “ignore” is a better default than “background”. Whether I’m right about having “ignore” as default can be discussed as there are pros and cons to both.

The line shouldn’t matter, but I think it doesn’t like blank lines included.

I understand the argument for the 255 default, but not the source of ‘usually’. If there are enough other libraries/pipelines that make this assumption then it may be worth changing; for any export I’ve made so far I’ve always wanted the background 0 and done any further processing elsewhere. The benefit of having 0 in the background is that the maximum pixel value can be used to immediately ascertain the number of labels, without needing to filter out 255’s separately. And 0 is also a more suitable default for binary classification problems. So I remain unconvinced… anyhow, it should be possible to set the background value to something else when required, which I think is the main thing.

1 Like