calculate_image_features

calculate_image_features#

squidpy.im.calculate_image_features(adata, *, img, layer=None, library_id=None, features='summary', features_kwargs=mappingproxy({}), key_added='img_features', copy=False, n_jobs=None, backend='loky', show_progress_bar=True, **kwargs)[source]#

Calculate image features for all observations in adata.

Parameters:
adata AnnData

Annotated data object.

img ImageContainer

High-resolution image.

layer str | None (default: None)

Image layer in img that should be processed. If None and only 1 layer is present, it will be selected.

library_id str | Sequence[str] | None (default: None)

features Literal['texture', 'summary', 'histogram', 'segmentation', 'custom'] | Sequence[Literal['texture', 'summary', 'histogram', 'segmentation', 'custom']] (default: 'summary')

Features to be calculated. Valid options are:

features_kwargs Mapping[str, Mapping[str, Any]] (default: mappingproxy({}))

Keyword arguments for the different features that should be generated, such as { 'texture': { ... }, ... }.

key_added str (default: 'img_features')

Key in anndata.AnnData.obsm where to store the calculated features.

copy bool (default: False)

If True, return the result, otherwise save it to the adata object.

n_jobs int | None (default: None)

Number of parallel jobs to use. None is serial and -1 uses all available cores; asking for more cores than are available warns and falls back to all of them, while 0 and values below -1 raise, since scanpy only supports n_jobs >= -1. For backend="loky", the number of cores used by numba for each job spawned by the backend will be set to 1 in order to overcome the oversubscription issue in case you run numba in your function to parallelize. To set the absolute maximum number of threads in numba for your python program, set the environment variable: NUMBA_NUM_THREADS before running the program.

backend str (default: 'loky')

Parallelization backend to use. See joblib.Parallel for available options.

show_progress_bar bool (default: True)

Whether to show the progress bar or not.

kwargs Any

Keyword arguments for squidpy.im.ImageContainer.generate_spot_crops().

Returns:

DataFrame | None – If copy = True, returns a pandas.DataFrame where columns correspond to the calculated features.

Otherwise, modifies the adata object with the following key:

Raises:

ValueError – If a feature is not known.