Skip to content

detect_tissue

Run simple/deterministic tissue detection algorithms based on a filter query, to reduce tiles to those (likely) to contain actual tissue Args: slide_urlpath (str): url/path to slide image (virtual slide formats compatible with pyvips, .svs, .tif, .scn, ...) tiles_urlpath (str): url/path to tiles manifest (parquet) filter_query (str): pandas query by which to filter tiles based on their various tissue detection scores tile_size (int): size of tiles to use (at the requested magnification) thumbnail_magnification (Optional[int]): Magnification scale at which to create thumbnail for tissue detection tile_magnification (Optional[int]): Magnification scale at which to generate tiles batch_size (int): batch size for processing output_urlpath (str): Output url/path force (bool): overwrite outputs if they exist dask_options (dict): dask options storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions local_config (str): local config file Returns: dict: metadata about cli function call

Source code in src/luna/pathology/cli/run_tissue_detection.py
@timed
@save_metadata
def cli(
    slide_urlpath: str = "???",
    tiles_urlpath: str = "",
    filter_query: str = "???",
    tile_size: Optional[int] = None,
    thumbnail_magnification: Optional[int] = None,
    tile_magnification: Optional[int] = None,
    batch_size: int = 2000,
    output_urlpath: str = ".",
    force: bool = False,
    dask_options: dict = {},
    storage_options: dict = {},
    output_storage_options: dict = {},
    local_config: str = "",
) -> dict:
    """Run simple/deterministic tissue detection algorithms based on a filter query, to reduce tiles to those (likely) to contain actual tissue
    Args:
        slide_urlpath (str): url/path to slide image (virtual slide formats compatible with pyvips, .svs, .tif, .scn, ...)
        tiles_urlpath (str): url/path to tiles manifest (parquet)
        filter_query (str): pandas query by which to filter tiles based on their various tissue detection scores
        tile_size (int): size of tiles to use (at the requested magnification)
        thumbnail_magnification (Optional[int]): Magnification scale at which to create thumbnail for tissue detection
        tile_magnification (Optional[int]): Magnification scale at which to generate tiles
        batch_size (int): batch size for processing
        output_urlpath (str): Output url/path
        force (bool): overwrite outputs if they exist
        dask_options (dict): dask options
        storage_options (dict): storage options to pass to reading functions
        output_storage_options (dict): storage options to pass to writing functions
        local_config (str): local config file
    Returns:
        dict: metadata about cli function call

    """
    config = get_config(vars())

    configure_dask_client(**config["dask_options"])

    if not config["tile_size"] and not config["tiles_urlpath"]:
        raise fire.core.FireError("Specify either tiles_urlpath or tile_size")

    slide_id = Path(config["slide_urlpath"]).stem

    tiles_urlpath = config["tiles_urlpath"]

    with make_temp_directory() as temp_dir:
        if not tiles_urlpath:
            result = __generate_tiles(
                config["slide_urlpath"],
                config["tile_size"],
                temp_dir,
                config["force"],
                config["tile_magnification"],
                config["storage_options"],
            )
            tiles_urlpath = result["tiles_url"]

        properties = __detect_tissue(
            config["slide_urlpath"],
            tiles_urlpath,
            slide_id,
            config["thumbnail_magnification"],
            config["filter_query"],
            config["batch_size"],
            config["output_urlpath"],
            config["force"],
            config["storage_options"],
            config["output_storage_options"],
        )

    return properties