squidpy.im.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) – Image layer inimgthat should be processed. If None and only 1 layer is present, it will be selected.library_id (
str|Sequence[str] |None) –If None, there should only exist one entry in
anndata.AnnData.uns['{spatial_key}'].If a
str, first searchanndata.AnnData.obs['{library_id}']which contains the mapping from observations to library ids, then searchanndata.AnnData.uns['{spatial_key}'].
features (
str|Sequence[str]) –Features to be calculated. Valid options are:
’texture’ - summary stats based on repeating patterns
squidpy.im.ImageContainer.features_texture().’summary’ - summary stats of each image channel
squidpy.im.ImageContainer.features_summary().’histogram’ - counts in bins of image channel’s histogram
squidpy.im.ImageContainer.features_histogram().’segmentation’ - stats of a cell segmentation mask
squidpy.im.ImageContainer.features_segmentation().’custom’ - extract features using a custom function
squidpy.im.ImageContainer.features_custom().
features_kwargs (
Mapping[str,Mapping[str,Any]]) – Keyword arguments for the different features that should be generated, such as{ 'texture': { ... }, ... }.key_added (
str) – Key inanndata.AnnData.obsmwhere to store the calculated features.copy (
bool) – IfTrue, return the result, otherwise save it to theadataobject.n_jobs (
int|None) – Number of parallel jobs to use. Forbackend="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_THREADSbefore running the program.backend (
str) – Parallelization backend to use. Seejoblib.Parallelfor available options.show_progress_bar (
bool) – Whether to show the progress bar or not.kwargs (
Any) – Keyword arguments forsquidpy.im.ImageContainer.generate_spot_crops().
- Return type:
DataFrame|None- Returns:
If
copy = True, returns apandas.DataFramewhere columns correspond to the calculated features.Otherwise, modifies the
adataobject with the following key:anndata.AnnData.uns['{key_added}']- the above mentioned dataframe.
- Raises:
ValueError – If a feature is not known.