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
imgthat should be processed. If None and only 1 layer is present, it will be selected.- library_id
str|Sequence[str] |None(default: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
Literal['texture','summary','histogram','segmentation','custom'] |Sequence[Literal['texture','summary','histogram','segmentation','custom']] (default:'summary') 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]] (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.obsmwhere to store the calculated features.- copy
bool(default:False) If
True, return the result, otherwise save it to theadataobject.- n_jobs
int|None(default:None) Number of parallel jobs to use. None is serial and
-1uses all available cores; asking for more cores than are available warns and falls back to all of them, while0and values below-1raise, since scanpy only supportsn_jobs >= -1. 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(default:'loky') Parallelization backend to use. See
joblib.Parallelfor 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().
- adata
- Returns:
DataFrame|None– Ifcopy = 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.