AnnotationRenderer#
- class AnnotationRenderer(score_prop=None, mapper=None, where=None, score_fn=<function AnnotationRenderer.<lambda>>, max_scale=8)[source]#
Renderer containing information and methods to render annotations from an AnnotationStore to a tile.
- Parameters:
score_prop (str) – A key that is present in the properties of annotations to be rendered that will be used to color rendered annotations.
mapper (str, Dict or List) – A dictionary or colormap used to color annotations according to the value of properties[score_prop] of an annotation. Should be either a matplotlib colormap, a string which is a name of a matplotlib colormap, a dict of possible property {value: color} pairs, or a list of categorical property values (in which case a dict will be created with a random color generated for each category).
where (str or Callable) – a callable or predicate which will be passed on to AnnotationStore.query() when fetching annotations to be rendered (see
tiatoolbox.annotation.storage.AnnotationStore
for more details).score_fn (Callable) – an optional callable which will be called on the value of the property that will be used to generate the color before giving it to colormap. Use it for example to normalise property values if they do not fall into the range [0,1], as matplotlib colormap expects values in this range. i.e., roughly speaking annotation_color=mapper(score_fn(ann.properties[score_prop])).
max_scale (int) – downsample level above which Polygon geometries on crowded tiles will be rendered as a bounding box instead.
Methods
Get the color for an annotation.
Render a line annotation onto a tile using cv2.
Render a polygon annotation onto a tile using cv2.
Render a point annotation onto a tile using cv2.
Render a box annotation onto a tile using cv2.
Return coords relative to top left of tile, as array suitable for cv2.
- get_color(annotation)[source]#
Get the color for an annotation. :param annotation: Annotation to get color for. :type annotation: Annotation
- Returns:
A color tuple (rgba).
- Return type:
- Parameters:
annotation (Annotation) –
- render_line(tile, annotation, top_left, scale)[source]#
Render a line annotation onto a tile using cv2. :param tile: The rgb(a) tile image to render onto. :type tile: ndarray :param annotation: The annotation to render. :type annotation: Annotation :param top_left: The top left corner of the tile in wsi. :type top_left: tuple :param scale: The zoom scale at which we are rendering. :type scale: int
- render_poly(tile, annotation, top_left, scale)[source]#
Render a polygon annotation onto a tile using cv2. :param tile: The rgb(a) tile image to render onto. :type tile: ndarray :param annotation: The annotation to render. :type annotation: Annotation :param top_left: The top left corner of the tile in wsi. :type top_left: tuple :param scale: The zoom scale at which we are rendering. :type scale: int
- render_pt(tile, annotation, top_left, scale)[source]#
Render a point annotation onto a tile using cv2. :param tile: The rgb(a) tile image to render onto. :type tile: ndarray :param annotation: The annotation to render. :type annotation: Annotation :param top_left: The top left corner of the tile in wsi. :type top_left: tuple :param scale: The zoom scale at which we are rendering. :type scale: int
- render_rect(tile, annotation, top_left, scale)[source]#
Render a box annotation onto a tile using cv2. :param tile: The rgb(a) tile image to render onto. :type tile: ndarray :param annotation: The annotation to render. :type annotation: Annotation :param top_left: The top left corner of the tile in wsi. :type top_left: tuple :param scale: The zoom scale at which we are rendering. :type scale: int
- static to_tile_coords(coords, top_left, scale)[source]#
Return coords relative to top left of tile, as array suitable for cv2. :param coords: List of coordinates in the form [x, y]. :type coords: List :param top_left: The top left corner of the tile in wsi. :type top_left: tuple :param scale: The zoom scale at which we are rendering. :type scale: int