Skip to content

generate_mask

Generate a full resolution mask image (.tif) from vector annotations (polygons, shapes)

 Inputs: input_slide_image: slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) input_slide_roi: roi containing vector shapes (.annotations, .json)  Outputs: slide_mask  Example: generate_mask ./slides/10001.svs ./halo/10001.job18484.annotations -an Tumor -o ./masks/10001/

Source code in src/luna/pathology/cli/generate_mask.py
@timed
@save_metadata
def cli(
    slide_urlpath: str = "???",
    roi_urlpath: str = "???",
    output_urlpath: str = "???",
    annotation_name: str = "???",
    storage_options: dict = {},
    output_storage_options: dict = {},
    local_config: str = "",
):
    """Generate a full resolution mask image (.tif) from vector annotations (polygons, shapes)

    \b
    Inputs:
        input_slide_image: slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...)
        input_slide_roi: roi containing vector shapes (*.annotations, *.json)
    \b
    Outputs:
        slide_mask
    \b
    Example:
        generate_mask ./slides/10001.svs ./halo/10001.job18484.annotations
            -an Tumor
            -o ./masks/10001/
    """
    config = get_config(vars())
    df = generate_mask(
        config["slide_urlpath"],
        config["roi_urlpath"],
        config["output_urlpath"],
        config["annotation_name"],
        config["storage_options"],
        config["output_storage_options"],
    )

    fs, output_urlpath_prefix = fsspec.core.url_to_fs(
        config["output_urlpath"], **config["output_storage_options"]
    )
    output_filename = Path(output_urlpath_prefix) / "mask_data.parquet"
    with fs.open(output_filename, "wb") as of:
        df.to_parquet(of)

    slide_id = Path(config["roi_urlpath"]).stem
    properties = {
        "slide_mask": Path(output_urlpath_prefix) / "mask_full_res.tif",
        "feature_data": output_filename,
        "mask_size": df["mask_size"].tolist(),
        "segment_keys": {"slide_id": slide_id},
    }

    return properties