使用histolab模块将WSI剪切成多个patch
histolab模块一共提供了三种提取patch的方式:
- Random Extraction
- Grid Extraction
- Score-based extraction
本文仅提供基于评分的提取方式:
import os
from histolab.slide import Slide
from histolab.tiler import ScoreTiler
from histolab.scorer import NucleiScorer
BASE_PATH = os.getcwd()
WSI_PATH = os.path.join(BASE_PATH, 'WSIs', 'TCGA-49-AAR4-01A.svs')
PATCH_PATH = os.path.join(BASE_PATH, 'patches')
wsi_slide = Slide(WSI_PATH, processed_path=PATCH_PATH)
scored_tiles_extractor = ScoreTiler(
scorer = NucleiScorer(),
tile_size=(256, 256),
n_tiles=15,
level=0,
check_tissue=True,
tissue_percent=80.0,
pixel_overlap=0, # default
prefix="/hy-tmp/patches/", # save tiles in the "scored" subdirectory of slide's processed_path
suffix=".png" # default
)
scored_tiles_extractor.locate_tiles(slide = wsi_slide)
summary_filename = "TCGA-49-AAR4-01A-tiles.csv"
SUMMARY_PATH = os.path.join(wsi_slide.processed_path, summary_filename)
scored_tiles_extractor.extract(wsi_slide, report_path=SUMMARY_PATH)
scored_tiles_extractor : 定义了提取器的参数。
tile_size : 每个patch的大小
n_tiles : 提取的patch个数
prefix : patch的输出路径(精确到png文件的上一级目录)
用scored_tiles_extractor.extract进行patch提取。
wsi_slide :是WSI_PATH(精确到svs文件名)路径下的Slide对象。且wsi_slide的processed_path属性值是svs文件的上一级路径。
report_path : 对应SUMMARY_PATH,是报告文件csv的路径。
其中report(csv文件)内容如下:
参考
https://pypi.org/project/histolab/