Open nodp53 opened 4 years ago
Thanks for the suggestion! I'll add this to the feature roadmap. Shouldn't be too hard to implement
this feature would be very useful to me, as I am dealing with images that have different base resolutions. let me know if i can help in any way!
@manuel-munoz-aguirre - could you suggest how to implement this feature? i can make a PR but i'm not sure how to best do this.
given an openslide image, would we first try to figure out the best level to use (i.e., get the highest resolution that is close to our target mpp)? once we have that level, we would extract a patch and then resize it to the desired mpp?
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:
def fit_tiles(vi, dims=DIMS):
resized dimensions
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
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, relativepaths=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.readcsv() 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