Skip to content

Commit

Permalink
Add warnings when no tissue is found
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Jun 10, 2024
1 parent a943830 commit f45aed9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lazyslide/pp/tissue_segment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import warnings

import numpy as np

Expand All @@ -27,8 +28,15 @@ def find_tissue(
# Get optimal level for segmentation
if level is None:
metadata = wsi.metadata
search_space = np.asarray(metadata.level_downsample) * metadata.mpp
level = np.argmin(np.abs(search_space - TARGET))
if metadata.mpp is None:
# Use the middle level
level = metadata.n_level // 2
warnings.warn(
f"mpp is not available, " f"use level {level} for segmentation."
)
else:
search_space = np.asarray(metadata.level_downsample) * metadata.mpp
level = np.argmin(np.abs(search_space - TARGET))
else:
level = wsi.reader.translate_level(level)

Expand Down Expand Up @@ -63,6 +71,9 @@ def find_tissue(
holes.append((hole * downsample))
holes_ids.append(tissue.id)

if len(contours) == 0:
logging.warning("No tissue is found.")
return
wsi.add_contours(contours, data={"tissue_id": contours_ids}, name=f"{key}_contours")
if len(holes) > 0:
wsi.add_holes(holes, data={"tissue_id": holes_ids}, name=f"{key}_holes")

0 comments on commit f45aed9

Please sign in to comment.