squidpy.experimental.im.calculate_image_features
- squidpy.experimental.im.calculate_image_features(sdata, image_key=None, labels_key=None, shapes_key=None, scale=None, channels=None, features=None, tile_size=2048, overlap_margin='auto', align_mode='strict', adata_key_added='morphology', invalid_as_zero=True, n_jobs=1, inplace=True)[source]
Calculate per-cell features from segmentation masks.
Uses scikit-image
regionpropsfor morphological/intensity features and squidpy-specific per-cell metrics (summary statistics, GLCM texture, colour histograms). Large images are automatically tiled intotile_size x tile_sizechunks with overlap so that every cell is fully contained in exactly one tile.- Parameters:
sdata (
SpatialData) – SpatialData object.image_key (
str|None) – Key insdata.images. Optional: required only for intensity / squidpy features (and forshapes_key). Morphology-only runs need no image.labels_key (
str|None) – Key insdata.labelswith segmentation masks.shapes_key (
str|None) – Key insdata.shapes(rasterized to labels internally).channels (
list[str] |None) – Subset of channel names to use, matching those returned byspatialdata.models.get_channel_names().Noneuses all channels. Integer indices are not accepted – always pass names.features (
list[str] |str|None) –Which features to compute (required;
Noneis rejected). A list of flag strings drawn from two groups:skimage regionprops –
"skimage:morphology"(all shape props, from the mask alone) or"skimage:morphology:<prop>"for one (e.g.area);"skimage:intensity"(all per-channel intensity props, needs an image) or"skimage:intensity:<prop>"for one (e.g.intensity_mean). Morphology columns use skimage’s native names (area,centroid-0); intensity columns are suffixed with the channel name.squidpy per-cell –
"squidpy:summary"(per-channel mean / std / min / max),"squidpy:texture"(per-channel GLCM contrast, dissimilarity, homogeneity, energy, ASM, correlation), and"squidpy:color_hist"(per-channel intensity histogram).
tile_size (
int) – Side length of the tiling grid (pixels).overlap_margin (
Union[int,Literal['auto']]) – Overlap around each tile to capture boundary cells."auto"computes the minimum from the largest cell’s bounding box.align_mode (
Literal['strict']) – Only"strict"is supported: require image and labels to share the same pixel grid (same y/x sizes). Raise otherwise.adata_key_added (
str) – Key under which to store the result insdata.tables.invalid_as_zero (
bool) – ReplaceinfandNaNvalues with zero.n_jobs (
int) – Number of parallel jobs for tile processing.inplace (
bool) – IfTrue, store result insdata.tables. Otherwise return it.
- Return type:
- Returns:
AnnDatawheninplace=False, otherwiseNone.
Examples
>>> import squidpy as sq >>> sq.experimental.im.calculate_image_features( ... sdata, ... image_key="image", ... labels_key="cells", ... features=["skimage:morphology", "skimage:intensity", "squidpy:summary"], ... )
Morphology-only needs no image:
>>> sq.experimental.im.calculate_image_features( ... sdata, labels_key="cells", features=["skimage:morphology:area"] ... )
The per-cell table is stored in
sdata.tables["morphology"].