Skip to content

visualize_tiles_png

Generate nice tile markup images with continuous or discrete tile scores

Parameters:

Name Type Description Default
slide_urlpath str

url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...)

'???'
tiles_urlpath str

url/path to a slide-tile manifest file (.tiles.csv)

''
mpp_units bool

if true, additional rescaling is applied to match micro-meter and pixel coordinate systems

False
plot_labels List[str]

labels to plot

'???'
output_urlpath str

output url/path prefix

'.'
requested_magnification int

Magnification scale at which to perform computation

None
tile_size int

tile size

None
storage_options dict

storage options to pass to reading functions

{}
output_storage_options dict

storage options to pass to writing functions

{}
local_config str

url/path to local config YAML file

''

Returns:

Name Type Description
dict

metadata about function call

Source code in src/luna/pathology/cli/visualize_tile_labels_png.py
@timed
@save_metadata
def cli(
    slide_urlpath: str = "???",
    tiles_urlpath: str = "",
    mpp_units: bool = False,
    plot_labels: List[str] = "???",  # type: ignore
    output_urlpath: str = ".",
    requested_magnification: Optional[int] = None,
    tile_size: Optional[int] = None,
    storage_options: dict = {},
    output_storage_options: dict = {},
    local_config: str = "",
):
    """Generate nice tile markup images with continuous or discrete tile scores

    Args:
        slide_urlpath (str): url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...)
        tiles_urlpath (str): url/path to a slide-tile manifest file (.tiles.csv)
        mpp_units (bool): if true, additional rescaling is applied to match micro-meter and pixel coordinate systems
        plot_labels (List[str]): labels to plot
        output_urlpath (str): output url/path prefix
        requested_magnification (int): Magnification scale at which to perform computation
        tile_size (int): tile size
        storage_options (dict): storage options to pass to reading functions
        output_storage_options (dict): storage options to pass to writing functions
        local_config (str): url/path to local config YAML file

    Returns:
        dict: metadata about function call
    """
    config = get_config(vars())

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

    thumbnails_overlayed = visualize_tiles(
        config["slide_urlpath"],
        config["tiles_urlpath"],
        config["mpp_units"],
        config["plot_labels"],
        config["requested_magnification"],
        config["tile_size"],
        config["storage_options"],
    )

    fs, output_path_prefix = fsspec.core.url_to_fs(
        config["output_urlpath"], **config["output_storage_options"]
    )

    images = {}
    for score_type, thumbnail_overlayed in thumbnails_overlayed.items():
        output_file = (
            Path(output_path_prefix)
            / f"tile_scores_and_labels_visualization_{score_type}.png"
        )
        thumbnail_overlayed = Image.fromarray(thumbnail_overlayed)
        with fs.open(output_file, "wb") as of:
            thumbnail_overlayed.save(of, format="PNG")
        images[score_type] = str(output_file)
        logger.info(f"Saved {score_type} visualization at {output_file}")

    properties = {
        "data": fs.unstrip_protocol(output_path_prefix),
        "images": images,
    }

    return properties