squidpy.im.ImageContainer.features_custom
- ImageContainer.features_custom(func, layer, channels=None, feature_name=None, **kwargs)
Calculate features using a custom function.
The feature extractor
funccan be anycallable(), as long as it has the following signature:numpy.ndarray(height, width, z, channels)->float/Sequence.- Parameters:
func (
Callable[[ndarray[tuple[Any,...],dtype[Any]]],Any]) – Feature extraction function.layer (
str|None) – Image layer inimgthat should be processed. If None and only 1 layer is present, it will be selected.channels (
int|Sequence[int] |None) – Channels for this feature is computed. If None, use all channels.feature_name (
str|None) – Base name of feature in resulting feature valuesdict.kwargs (
Any) – Keyword arguments forfunc. If additional_layers is present, all layers with the specified names will be passed tofunc. usingfunc(..., <layer-name>=<layer-values>)for each layer name in additional_layers.
- Return type:
- Returns:
Returns features with the following keys:
'{feature_name}_{i}'- i-th feature value.
Examples
Simple example would be to calculate the mean of a specified channel, as already done in
squidpy.im.ImageContainer.features_summary():img = squidpy.im.ImageContainer(...) img.features_custom(imd_id=..., func=numpy.mean, channels=0)