wsiprocess.annotationparser package

Submodules

wsiprocess.annotationparser.ASAP_parser module

class wsiprocess.annotationparser.ASAP_parser.ASAPAnnotation(path)

Bases: BaseParser

Annotation Parser for ASAP.

Parameters:

path (str) – Path to the annotation file.

path

Path to the annotation file.

Type:

str

annotations

List of etree Elements.

Type:

list

annotation_groups

List of etree Elements.

Type:

list

classes

List of classes defined with ASAP.

Type:

list

mask_coords

Coordinates of the masks.

Type:

dict

read_mask_coord(cls)

Parse the coordinates of the mask.

Parameters:

cls (str) – Target annotation class name.

read_mask_coords()

Parse coordinates of of the masks of all classes.

wsiprocess.annotationparser.GeoJson_parser module

class wsiprocess.annotationparser.GeoJson_parser.GeoJsonAnnotation(path)

Bases: BaseParser

Parser for GeoJson styled Annotation.

Example

>>> with open("xxx.geojson", "r") as f:
>>>     annotations = geojson.load(f)
>>> print(annotations)
>>> {
>>>     "type": "FeatureCollection",
>>>     "features": [
>>>         {
>>>             "type": "Feature",
>>>             "properties": {
>>>                 "class": 0
>>>             },
>>>             "geometry": {
>>>                 "type": "Polygon",
>>>                 "coordinates": [
>>>                     [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 0.0]]
>>>                 ]
>>>             }
>>>         }
>>>     ]
>>> }
read_annotation()

Read the annotation file.

wsiprocess.annotationparser.NDPView_parser module

class wsiprocess.annotationparser.NDPView_parser.Annotation(element: lxml.etree.Element, origin: Coord, mpp: MPP)

Bases: object

Annotations of NDP View.

Parameters:
  • element (etree.Element) – Element of the annotation.

  • origin (Coord) – Origin of the slide.

  • mpp (MPP) – MPP of the slide.

element

Element of the annotation.

Type:

etree.Element

title

Title of the annotation. Used as the class.

Type:

str

coordformat

Coordinate format.

Type:

str

type

Type of the annotation. One of AnnotateCircle, AnnotateFreehandLine, AnnotateRectangle, AnnotatePin, AnnotateFreehand

Type:

str

property coords
get_circle_coords() List[int]

Get the coordinates of the circle annotation.

get_coords()
get_pin_coords() List[int]

Get the coordinate of Pin annotation

get_polygon_coords() List[int]

Get coordinates of rectangle, freehand, freehandline polygons. The coordinates are assumed to be closed.

property title
class wsiprocess.annotationparser.NDPView_parser.Coord(x: float, y: float)

Bases: object

x: float
y: float
class wsiprocess.annotationparser.NDPView_parser.MPP(x: float, y: float, r: float)

Bases: object

meter2px(meter: float, axis: str, coordformat: str) float

Convert meter to pixel.

Parameters:
  • meter (float) – Length in meter.

  • axis (str) – mpp to use along this axis.

Returns:

Length in pixel.

Return type:

int

r: float
x: float
y: float
class wsiprocess.annotationparser.NDPView_parser.NDPViewAnnotation(path, slide)

Bases: BaseParser

Annotation Parser for NDP View. https://www.hamamatsu.com/jp/ja/product/life-science-and-medical-systems/digital-slide-scanner/U12388-01.html

Parameters:
  • path (str) – Path to the annotation file.

  • slide (wsiprocess.Slide) – Slide object.

path

Path to the annotation file.

Type:

str

annotations

List of etree Elements.

Type:

list

annotation_groups

List of etree Elements.

Type:

list

classes

List of classes defined with ASAP.

Type:

list

mask_coords

Coordinates of the masks.

Type:

dict

read_annotation(origin, mpp)
wsiprocess.annotationparser.NDPView_parser.get_mpp(slide)
wsiprocess.annotationparser.NDPView_parser.get_origin(slide, mpp: MPP, coordformat: str)

wsiprocess.annotationparser.QuPath_parser module

class wsiprocess.annotationparser.QuPath_parser.QuPathAnnotation(path)

Bases: BaseParser

Annotation Parser for QuPath.

Parameters:

path (str) – Path to the annotation file.

path

Path to the annotation file.

Type:

str

annotations

List of etree Elements.

Type:

list

classes

List of classes defined with QuPath.

Type:

list

mask_coords

Coordinates of the masks.

Type:

dict

all_as_int(points)
read_classes()
read_coordinates()

Parse the coordinates of the mask.

wsiprocess.annotationparser.SlideRunner_parser module

class wsiprocess.annotationparser.SlideRunner_parser.SlideRunnerAnnotation(path, slide)

Bases: BaseParser

Annotation Parser for SlideRunner v1.31.0

Parameters:
  • path (str) – Path to the annotation file.

  • slide (wsiprocess.Slide) – Slide object.

path

Path to the annotation file.

Type:

str

classes

List of classes defined with ASAP.

Type:

list

mask_coords

Coordinates of the masks.

Type:

dict

bbox_to_circle(left, top, right, bottom)

Convert coordinates of bounding box to circle.

Parameters:
  • left (int) – Smaller coordinate of in the x-axis direction

  • top (int) – Smaller coordinate of in the y-axis direction

  • right (int) – Larger coordinate of in the x-axis direction

  • bottom (int) – Larger coordinate of in the y-axis direction

Returns:

List of list which contains one

coordinate representing a circle in coordinates.

Return type:

coordinate (list(list))

parse_mask_coords()

Parse the coordinates of the mask.

Parse the coordinates to make a list containing lists of coordinates.

read_annotations(slidename)

Read annotations from Annotations table.

A annotation has unique ID, Annotation Type, and Class.

Parameters:

slidename (str) – Name of the slide to filter the data.

read_classes()

Read classes from Classes table.

read_coordinates(slidename)

Read coordinates from Annotations_coordinates table.

A coordinate has coordinate of x and y, Annotation ID and the order of the coordinate.

Parameters:

slidename (str) – Name of the slide to filter the data.

read_labels()

Read labels from Annotations_label table.

A label has Annotation ID (sharing with Annotations), and Class.

read_slides()

Read slides from Slides table. A slide has unique ID and filename.

verify_annotations()

Verify the number of annotations.

The numbers of annotations and labels and coordinates must be same.

wsiprocess.annotationparser.WSIDissector_parser module

class wsiprocess.annotationparser.WSIDissector_parser.WSIDissectorAnnotation(path)

Bases: BaseParser

Annotation parser for WSIDissector

Parameters:

path (str) – Path to the annotation file.

path

Path to the annotation file.

Type:

str

annotation

Annotation data loaded as json file.

Type:

dict

filename

Name of the targeted whole slide image file.

Type:

str

classes

List of the names of the classes.

Type:

list

mask_coords

Coordinates of the masks.

Type:

dict

read_mask_coords()

Parse the coordinates of masks.

wsiprocess.annotationparser.parser_utils module

class wsiprocess.annotationparser.parser_utils.BaseParser(path)

Bases: object

Base class for Parsers

wsiprocess.annotationparser.parser_utils.detect_type(path)

Detect the type of input file.

Returns:

One of {“ASAP”, “WSIDissector”, “SlideRunner”,

”WSIDissector”, “Empty”}

Return type:

file_type (str)

Module contents