Skip to content

Commit

Permalink
better interface for WholeSlideImage.save_tile_images
Browse files Browse the repository at this point in the history
  • Loading branch information
afrendeiro committed Mar 29, 2024
1 parent 813e6ff commit f8fbf1d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions wsi/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
Image.MAX_IMAGE_PIXELS = 933120000


# TODO: replace contours_tumor with a generic label field
# TODO: make function to plot contours (colored by label field)


class WholeSlideImage(object):
def __init__(
self,
path: Path | _Path | str,
path: Path | str,
*,
attributes: tp.Optional[dict[str, tp.Any]] = None,
mask_file: Path | None = None,
Expand Down Expand Up @@ -847,7 +851,7 @@ def get_tile_images(
def save_tile_images(
self,
output_dir: Path,
format: str = "jpg",
output_format: str = "jpg",
attributes: bool = True,
n: int | None = None,
frac: float = 1.0,
Expand All @@ -859,7 +863,7 @@ def save_tile_images(
----------
output_dir: Path
Directory to save tile images to.
format: str
output_format: str
File format to save images as.
attributes: bool
Whether to include attributes in filename.
Expand Down Expand Up @@ -900,8 +904,8 @@ def save_tile_images(
sel = pd.Series(range(nc)).sample(frac=frac, n=n).values

for coord in coords[sel]:
# Output in the form of: slide_name.attr[0].attr[1].attr[n].x.y.format
fp = output_dir / (output_prefix + f".{coord[0]}.{coord[1]}.{format}")
# Output in the form of: slide_name.attr[0].attr[1].attr[n].x.y.output_format
fp = output_dir / (output_prefix + f".{coord[0]}.{coord[1]}.{output_format}")
img = self.wsi.read_region(coord, level=level, size=(size, size))
img.convert("RGB").save(fp)

Expand Down

0 comments on commit f8fbf1d

Please sign in to comment.