lazyslide.seg.cells#
- cells(wsi, model='instanseg', tile_key='tiles', magnification=None, transform=None, batch_size=4, num_workers=0, device=None, amp=None, autocast_dtype=None, size_filter=False, nucleus_size=(20, 1000), pbar=True, extract_features=False, low_memory=False, postprocess_workers=0, overlap_ownership=False, key_added='cells', **model_kwargs)#
cell segmentation for the whole slide image.
tile should be prepared before segmentation, the tile size should be reasonable (with mpp around 0.5) for the model to work properly
Supported models:
instanseg [Goldsborough et al., 2024]
cellpose [Stringer et al., 2021]
nulite [Tommasino et al., 2024]
histoplus [Adjadj et al., 2025]
- Parameters:
- wsi
WSIData The WSIData object to work on.
- modelstr or SegmentationModelProtocol, default: “instanseg”
The cell segmentation model.
- tile_keystr, default: “tiles”
The key of the tile table.
- magnificationstr, default: None
The magnification of the model. Used by cell type segmentation models.
- transformcallable, default: None
The transformation for the input tiles.
- batch_sizeint, default: 4
The batch size for segmentation.
- num_workersint, default: 0
The number of workers for data loading.
- devicestr, default: None
The device for the model.
- ampbool, optional
Whether to use automatic mixed precision.
- autocast_dtypetorch.dtype, optional
The dtype for automatic mixed precision.
- size_filterbool, default: False
Whether to filter cells by nucleus size.
- nucleus_sizetuple of (int, int), default: (20, 1000)
The (min, max) nucleus size range in pixels for filtering. Only used when
size_filter=True.- pbarbool, default: True
Whether to show a progress bar during segmentation.
- extract_featuresbool, default: False
Whether to extract per-cell feature vectors from the model’s
patch_token_map. Only available for ViT-based segmentation models (e.g. NuLite, HistoPLUS). If the model does not produce apatch_token_map, a warning is emitted and features are skipped.- low_memorybool, default: False
When
extract_features=True, write intermediate feature chunks to on-disk mmap files and only materialize features that survive filtering and NMS.- postprocess_workersint, default: 0
Number of CPU threads used to polygonize completed inference batches. Set to 1 to overlap GPU inference with CPU postprocessing. In-flight work is bounded to two batches per worker.
- overlap_ownershipbool, default: False
For overlapping tiles, polygonize an instance only in the covering tile whose center is nearest to its centroid. This removes most duplicate polygonization while retaining NMS as a safety net.
- key_addedstr, default: “cells”
The key for the added cell shapes.
- wsi
- Returns:
- None
The cell shapes are added to the shapes slot of the WSIData object.