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

✨ Add on-the-fly Registered Slide Visualization #875

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tiatoolbox/visualization/bokeh_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,13 @@ def populate_layer_list(slide_name: str, overlay_path: Path) -> None:
"*.jpg",
"*.json",
"*.tiff",
"*.mrxs",
"*.ndpi",
"*.svs",
"*.tif",
"*.npy",
"*.mha",
]:
file_list.extend(list(overlay_path.glob(str(Path("*") / ext))))
file_list.extend(list(overlay_path.glob(ext)))
file_list = [(str(p), str(p)) for p in sorted(file_list) if slide_name in str(p)]
UI["layer_drop"].menu = file_list
Expand All @@ -726,7 +731,6 @@ def populate_slide_list(slide_folder: Path, search_txt: str | None = None) -> No
file_list = []
len_slidepath = len(slide_folder.parts)
for ext in ["*.svs", "*ndpi", "*.tiff", "*.mrxs", "*.jpg", "*.png", "*.tif"]:
file_list.extend(list(Path(slide_folder).glob(str(Path("*") / ext))))
file_list.extend(list(Path(slide_folder).glob(ext)))
if search_txt is None:
file_list = [
Expand Down Expand Up @@ -1003,7 +1007,8 @@ def layer_drop_cb(attr: MenuItemClick) -> None:
if Path(attr.item).suffix in [".db", ".dat", ".geojson"]:
update_ui_on_new_annotations(resp)
else:
add_layer(resp)
if resp != "slide":
add_layer(resp)
change_tiles(resp)


Expand Down
18 changes: 17 additions & 1 deletion tiatoolbox/visualization/tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from tiatoolbox.tools.pyramid import AnnotationTileGenerator, ZoomifyGenerator
from tiatoolbox.utils.misc import add_from_dat, store_from_dat
from tiatoolbox.utils.visualization import AnnotationRenderer, colourise_image
from tiatoolbox.wsicore.wsireader import OpenSlideWSIReader, VirtualWSIReader, WSIReader
from tiatoolbox.wsicore.wsireader import (
OpenSlideWSIReader,
TransformedWSIReader,
VirtualWSIReader,
WSIReader,
)

if TYPE_CHECKING: # pragma: no cover
from matplotlib.colors import Colormap
Expand Down Expand Up @@ -510,6 +515,17 @@
overlay_path = request.form["overlay_path"]
overlay_path = self.decode_safe_name(overlay_path)

if overlay_path.suffix in [".npy", ".mha"]:
# loading a registration transformation
self.layers[session_id]["slide"] = TransformedWSIReader(

Check warning on line 520 in tiatoolbox/visualization/tileserver.py

View check run for this annotation

Codecov / codecov/patch

tiatoolbox/visualization/tileserver.py#L520

Added line #L520 was not covered by tests
self.layers[session_id]["slide"].info.file_path,
transform=overlay_path,
)
self.pyramids[session_id]["slide"] = ZoomifyGenerator(

Check warning on line 524 in tiatoolbox/visualization/tileserver.py

View check run for this annotation

Codecov / codecov/patch

tiatoolbox/visualization/tileserver.py#L524

Added line #L524 was not covered by tests
self.layers[session_id]["slide"],
)
return json.dumps("slide")

Check warning on line 527 in tiatoolbox/visualization/tileserver.py

View check run for this annotation

Codecov / codecov/patch

tiatoolbox/visualization/tileserver.py#L527

Added line #L527 was not covered by tests

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