DIAGNijmegen / pathology-whole-slide-data

A package for working with whole-slide data including a fast batch iterator that can be used to train deep learning models.
https://diagnijmegen.github.io/pathology-whole-slide-data/
Apache License 2.0
86 stars 24 forks source link

AsapAnnotationParser label colors from group #29

Closed robinlomans closed 1 year ago

robinlomans commented 1 year ago

Hi @martvanrijthoven,

Can the AsapAnnotationParser be changed such that the parsed label color is the color of the group, instead of the individual annotation color? I think this behavior would make sense since the parser also takes the label name from the group, instead of the individual annotation name.

I think the simplest way to achieve this would be to pass the root element to the _get_label method of AsapAnnotationParser, and modify the method to:


    def _get_label(self, child, root, labels: Labels, type):
        name = self._get_label_name(child, labels, type)
        if name not in labels.names:
            return None

        label = labels.get_label_by_name(name)
        label = label.todict()
        root.find(f".//Group[@Name='{name}']").get("Color")
        if 'color' not in label or label['color'] is None:
            if color:
                label["color"] = color

        return label
martvanrijthoven commented 1 year ago

Hi Robin,

Nice solution, thanks for the contribution. I pushed some changes. Please let me know if it does not work as expected.