Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕 Address TIAViz Review Comments #841

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
14 changes: 14 additions & 0 deletions tiatoolbox/annotation/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,20 @@ def transform_geometry(geom: Geometry) -> Geometry:
)
for feature in geojson["features"]
]
# check for presence of 'nucleusGeometry' key in features
# if present, add them (qupath export format)
annotations += [
transform(
Annotation(
transform_geometry(
feature2geometry(feature["nucleusGeometry"]),
),
{},
),
)
for feature in geojson["features"]
if "nucleusGeometry" in feature
]

logger.info("Adding %d annotations.", len(annotations))
self.append_many(annotations)
Expand Down
36 changes: 34 additions & 2 deletions tiatoolbox/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,41 @@ def render_pt(
top_left,
scale,
)[0][0],
np.maximum(self.edge_thickness, 1),
np.maximum(int(16 / scale**0.5), 1),
col,
thickness=self.thickness,
thickness=-1,
)

def render_pts(
self: AnnotationRenderer,
tile: np.ndarray,
annotation: Annotation,
top_left: tuple[float, float],
scale: float,
) -> None:
"""Render a multipoint annotation onto a tile using cv2.

Args:
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.

"""
col = self.get_color(annotation, edge=False)
for pt in annotation.coords:
cv2.circle(
tile,
self.to_tile_coords([pt], top_left, scale)[0][0],
np.maximum(int(16 / scale**0.5), 1),
col,
thickness=-1,
)

def render_line(
self: AnnotationRenderer,
tile: np.ndarray,
Expand Down Expand Up @@ -1052,5 +1082,7 @@ def render_by_type(
self.render_poly(tile, annotation, top_left, scale)
elif geom_type == GeometryType.LINE_STRING:
self.render_line(tile, annotation, top_left, scale)
elif geom_type == GeometryType.MULTI_POINT:
self.render_pts(tile, annotation, top_left, scale)
else:
logger.warning("Unknown geometry: %s", geom_type, stacklevel=3)
5 changes: 3 additions & 2 deletions tiatoolbox/visualization/bokeh_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def add_layer(lname: str) -> None:
end=1,
value=0.75,
step=0.01,
title=lname,
height=40,
width=100,
max_width=90,
Expand Down Expand Up @@ -1053,7 +1052,9 @@ def layer_slider_cb(
UI["vstate"].layer_dict[obj.name.split("_")[0]]
].glyph.line_alpha = new
else:
UI["p"].renderers[UI["vstate"].layer_dict[obj.name.split("_")[0]]].alpha = new
UI["p"].renderers[
UI["vstate"].layer_dict["_".join(obj.name.split("_")[0:-1])]
].alpha = new


def color_input_cb(
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/visualization/tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def change_overlay(self: TileServer) -> str:
overlay_path = self.decode_safe_name(overlay_path)

if overlay_path.suffix in [".jpg", ".png", ".tiff", ".svs", ".ndpi", ".mrxs"]:
layer = f"layer{len(self.pyramids[session_id])}"
layer = overlay_path.stem
if overlay_path.suffix == ".tiff":
self.layers[session_id][layer] = OpenSlideWSIReader(
overlay_path,
Expand Down
Loading