wsipipe.load.annotations package
All annotations are loaded in the generic annotation format. Individual modules convert specific annotation types to the generic
annotation module
Parent classes that contain functionality for reading annotations. These are used to render different types of annotations into a common format
- class Annotation(name, annotation_type, label, vertices)[source]
Bases:
object
Class for a single annotation.
There can be multiple annotations on a slide
- Parameters:
name (str) – Name of the annotation.
type (str) – One of Dot, Polygon, Spline or Rectangle
label (str) – What label should be given to the annotation
vertices (List[PointF]) – A list of vertices, each of which is an PointF object, a named tuple (x, y) of floats.
annotation_type (str) –
- draw(image, labels, factor)[source]
Renders the annotation into the image.
- Parameters:
image (np.array) – Array to write the annotations into, must have dtype float.
labels (Dict[str, int]) – The value to write into the image for each type of label.
factor (float) – How much to scale (by divison) each vertex by.
- class AnnotationSet(annotations, labels, labels_order, fill_label)[source]
Bases:
object
Class for all annotations on a slide.
- Parameters:
annotations (List[Annotation]) – A list of all Annotations on a slide
labels (Dict[str, int]) – A dictionary where the keys are the names of labels, with the integer values with which the string should be replaced.
labels_order (List[str]) – An order the labels should be plotted in. Where annotations overlap they will be drawn in this order, so the final label will be on top
fill_label (str) – The label given to any unannotated areas.
- render(shape, factor)[source]
Creates a labelled image containing annotations
This creates an array of size = shape, that is factor times smaller than the level at which the annotation vertexes are specified. Annotations vertex positions are assumed to be specified at level 0, and therefore for many WSI a np.array of the same size as level 0 would not fit in memory. Therefore one factor times smaller is created.
- Parameters:
shape (Shape) – size of numpy array to create
factor (float) – How much to scale (by divison) each vertex by.
- Return type:
numpy.array
- visualise_annotations(annot_path, slide_path, loader, level, slide_label)[source]
Creates a image render of the annotations of a slide
Converts annotations from level zero to the specified level. Requires slide path to find the correct dimensions of the output image. Returns a numpy array
- Parameters:
annot_path (Path) – A path to the annotation file
slide_path (Path) – A path to the WSI file
loader – The loader to use for slides and annots
level (int) – the level to create the numpy array
slide_label (str) –
- Returns:
An array the same size as the WSI at level with the annotation labels plotted in it.
- Return type:
labels_image (np.array)
asapxml module
Functions to load annotations stored in asapxml formats and convert to Annotation class formats
- annotation_from_tag(tag, group_labels)[source]
Convert an asapxml element to annotation format.
- Parameters:
tag (Element) – An element from the xml Element tree
group_labels (Dict[str, str]) – A dictionary of group labels that convert values stored in xml PartOfGroup to required label. e.g {“Tumor”: “tumor”, “Metastasis”: “tumor”, “Normal”: “normal”, “Tissue”: “normal”}
- Return type:
- load_annotations_asapxml(xml_file_path, group_labels)[source]
Read xml file and create annotations
- Parameters:
xml_file_path (Path) – PAth to xml file to read
group_labels (Dict[str, str]) – A dictionary of group labels that convert values stored in xml PartOfGroup (keys) to required label (values). e.g {“Tumor”: “tumor”, “Metastasis”: “tumor”, “Normal”: “normal”, “Tissue”: “normal”}
- Return type:
List[Annotation]