Support for find the whole-slide image (WSI) resolution (in microns per pixel, MPP) and extracting tiles with given MPP resolution #20
Labels
enhancement
New feature or request
Milestone
Hi Manuel, at first a real big thx to your for this excellent work. From project design to documentation wau. The first project where everything works as it should. Small suggestion from me would be the implementation of possibility of extraction the tiles with given MPP resolution. Maybe like this:
`import pathlib
import re
import datetime
import pyvips as vips
import pandas as pd
from wsi_tile_cleanup import filters, utils
from .timer import Timer
defaults
MPP = 0.5
DIMS = 224
FMT = ".png"
OUT_DIR = "."
def rescale_slide(vi, mpp=MPP, mpp_key="openslide.mpp-x"):
# TODO: generalize the mpp_key? some alternatives:
# - "aperio.MPP", "openslide.mpp-y", "openslide.mpp-x"
vi_mpp = float(vi.get(mpp_key))
mpp = float(mpp)
def fit_tiles(vi, dims=DIMS):
# resized dimensions
re_width = vi.width
re_height = vi.height
def center_crop(vi, coords):
fitted_width, fitted_height, excess_x, excess_y = coords
def deepzoom_save(vi, base_name, dir_name=OUT_DIR, dims=DIMS, file_format=FMT):
# as of pyvips 2.1.12: dir_name is required
# and not optional as the docs say
# https://libvips.github.io/pyvips/vimage.html#pyvips.Image.dzsave
def create_tiles(
slide_path, mpp=MPP, tile_dims=DIMS, file_format=FMT, output_dir=OUT_DIR
):
t = Timer()
def save_tiles_csv(output_path, file_format=FMT, relative_paths=True):
tiles = [_ for _ in output_path.glob(f"0/*{file_format}")]
print(f"- directory {output_path}/ has {len(tiles)} {file_format} tiles")
TODO: extract this function (it is repeated from filters.py)
def consolidate_tiles_csvs(output_dir, consolidated_csv, glob_pattern):
output_dir_path = pathlib.Path(output_dir)
dfs = [pd.read_csv(_) for _ in output_dir_path.glob(glob_pattern)]
consolidated_df = pd.concat(dfs, ignore_index=True)
consolidated_df.to_csv(consolidated_csv, index=False)
print(f"tiles info consolidated and saved to {consolidated_csv}")
def run_tiling(
slide_csv,
consolidated_csv,
output_dir=OUT_DIR,
mpp=MPP,
tile_dims=DIMS,
file_format=FMT,
):
slides_df = pd.read_csv(slide_csv)
slides_df = slides_df.convert_dtypes()
Taken from https://github.com/lucasrla/wsi-preprocessing
The text was updated successfully, but these errors were encountered: