AnnotationRenderer¶
- class AnnotationRenderer(score_prop=None, mapper=None, where=None, score_fn=<function AnnotationRenderer.<lambda>>, max_scale=8, zoomed_out_strat=10000, thickness=-1, edge_thickness=1, secondary_cmap=None, blur_radius=0, score_prop_edge=None, function_mapper=None)[source]¶
Renders AnnotationStore to a tile.
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 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
zoomed_out_strat (int, str) – strategy to use when rendering zoomed out tiles at a level above max_scale. Can be one of ‘decimate’, ‘scale’, or a number which defines the minimum area an abject has to cover to be rendered while zoomed out above max_scale.
thickness (int) – line thickness of rendered contours. -1 will render filled contours.
edge_thickness (int) – line thickness of rendered edges.
secondary_cmap (dict [str, str, cmap]) – a dictionary of the form {“type”: some_type, “score_prop”: a property name, “mapper”: a matplotlib cmap object}. For annotations of the specified type, the given secondary colormap will override the primary colormap.
blur_radius (int) – radius of gaussian blur to apply to rendered annotations.
score_prop_edge (str) – A key that is present in the properties of annotations to be rendered that will be used to color rendered edges.
function_mapper (Callable) – A callable which will be given the properties of an annotation and should return a color for the annotation. If this is specified, mapper and score_prop are ignored.
Initialize
AnnotationRenderer
.Methods
Get the color for an annotation.
Render annotations within given bounds.
Render annotation appropriately to its geometry type.
Render a line annotation onto a tile using cv2.
Render a multipolygon annotation onto a tile using cv2.
Render a polygon annotation onto a tile using cv2.
Render a point annotation onto a tile using cv2.
Return coords relative to top left of tile, as array suitable for cv2.
- get_color(annotation, *, edge)[source]¶
Get the color for an annotation.
- Parameters:
annotation (Annotation) – Annotation to get color for.
edge (bool) – Whether to get the color for the edge of the annotation, or the interior.
self (AnnotationRenderer)
- Returns:
A color tuple (rgba).
- Return type:
- render_annotations(store, bounds, scale, res=1, border=0)[source]¶
Render annotations within given bounds.
This gets annotations as bounding boxes or geometries according to zoom level, and renders them. Large collections of small annotation geometries are decimated if appropriate.
- Parameters:
store (AnnotationStore) – The annotation store to render from.
bounds (Polygon) – The bounding box of the tile to render.
scale (float) – The scale at which we are rendering the tile.
res (int) – The resolution of the tile. Defaults to 1. Can be set to 2 for higher resolution rendering.
border (int) – The border to add around the tile. Defaults to 0. Used for blurred rendering to avoid edge effects.
self (AnnotationRenderer)
- Returns:
The tile with the annotations rendered.
- Return type:
np.ndarray
- render_by_type(tile, annotation, top_left, scale)[source]¶
Render annotation appropriately to its geometry type.
- Parameters:
tile (np.ndarray) – The rgb(a) tile image to render the annotation on.
annotation (Annotation) – The annotation to render.
top_left (Tuple[int, int]) – The top left coordinate of the tile.
scale (float) – The scale at which we are rendering the tile.
self (AnnotationRenderer)
- Return type:
None
- render_line(tile, annotation, top_left, scale)[source]¶
Render a line annotation onto a tile using cv2.
- Parameters:
tile (ndarray) – The rgb(a) tile image to render onto.
annotation (Annotation) – The annotation to render.
top_left (tuple) – The top left corner of the tile in wsi.
scale (float) – The zoom scale at which we are rendering.
self (AnnotationRenderer)
- Return type:
None
- render_multipoly(tile, annotation, top_left, scale)[source]¶
Render a multipolygon annotation onto a tile using cv2.
- Parameters:
self (AnnotationRenderer)
tile (np.ndarray)
annotation (Annotation)
scale (float)
- Return type:
None
- render_poly(tile, annotation, top_left, scale)[source]¶
Render a polygon annotation onto a tile using cv2.
- Parameters:
tile (ndarray) – The rgb(a) tile image to render onto.
annotation (Annotation) – The annotation to render.
top_left (tuple) – The top left corner of the tile in wsi.
scale (float) – The zoom scale at which we are rendering.
self (AnnotationRenderer)
- Return type:
None
- render_pt(tile, annotation, top_left, scale)[source]¶
Render a point annotation onto a tile using cv2.
- Parameters:
tile (ndarray) – The rgb(a) tile image to render onto.
annotation (Annotation) – The annotation to render.
top_left (tuple) – The top left corner of the tile in wsi.
scale (float) – The zoom scale at which we are rendering.
self (AnnotationRenderer)
- Return type:
None