spatialrefinery.segmentation.instanseg.segment_wsi#
- spatialrefinery.segmentation.instanseg.segment_wsi(wsi_path, outdir, *, pixel_size=None, gpu_id=0, model_type='brightfield_nuclei', tile_size=512, overlap=80, detection_size=20, use_otsu_threshold=True, clahe_clip=None, seed_threshold=None, skip_existing=True)#
Segment nuclei in one whole-slide image and return the GeoJSON path.
- Parameters:
wsi_path (
str|Path) – The slide to segment. Read through tiffslide, so SVS/NDPI/OME-TIFF and other TIFF-backed formats work.outdir (
str|Path) – Parent directory. Results go to<outdir>/<wsi_path.name>/cells.geojson; the directory is named with the full filename (extension included) so thata.svsanda.ndpicannot collide. The zarr stage names its store for the stem instead (a.ome.tif->a.zarr); seeto_spatialdata.default_zarr_path.pixel_size (
float|None(default:None)) – Microns per pixel. Read from the slide metadata when omitted. InstanSeg rejects a value outside [0.1, 1] micron, so pass this explicitly for slides with missing or nonsensical resolution tags.gpu_id (
int|None(default:0)) – CUDA device index, or None to force CPU. Under the SLURM worker each process sees a single GPU viaCUDA_VISIBLE_DEVICES, so this stays 0.use_otsu_threshold (
bool(default:True)) – Skip tiles outside the tissue mask, so background is not segmented.clahe_clip (
float|None(default:None)) – Run CLAHE over each tile at this clip limit before inference. Off by default. Worth setting (2.0 is a reasonable start) on weakly haematoxylin-stained slides, where InstanSeg’s per-tile percentile normalisation leaves pale nuclei below the seed threshold: on a pale kidney H&E it recovered 22% more nuclei, and 27% together withseed_threshold=0.4.seed_threshold (
float|None(default:None)) – Override the model’s seed threshold (default 0.7). Lower detects fainter nuclei at some risk of over-segmentation.skip_existing (
bool(default:True)) – Return immediately ifcells.geojsonis already present, which makes an interrupted batch resumable.
- Return type:
- Returns:
Path The written
cells.geojson.