Labels#

from wholeslidedata.annotation.labels import Labels

Labels from list#

implicit value assignment

labels = Labels.create(['class_a', 'class_b'])
print(labels.map)
print(labels.names)
print(labels.values)
for label in labels:
    print(label.name, label.value)
{'class_a': 1, 'class_b': 2}
['class_a', 'class_b']
[1, 2]
class_a 1
class_b 2
labels = Labels.create(['class_a', 'class_a'])
print(labels.names, labels.values, labels.map)
['class_a'] [1, 2] {'class_a': 2}

Labels from dict#

explicit value assignment

labels = Labels.create({'class_a': 2, 'class_b': 1})
print(labels.map)
{'class_a': 2, 'class_b': 1}

Specific label creation with additional properties, e.g. color#

labels = Labels.create([{'name': 'class_a', 'value': 2, 'color': 'blue'},
                         {'name': 'class_b', 'value': 1, 'color': 'green'}])
for label in labels:
    print(label, label.name, label.value, label.color)
Label(name=class_a, value=2) class_a 2 blue
Label(name=class_b, value=1) class_b 1 green