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[Any]],Any] Feature extraction function.
- layer
str|None Image layer in
imgthat should be processed. If None and only 1 layer is present, it will be selected.- channels
int|Sequence[int] |None(default:None) Channels for this feature is computed. If None, use all channels.
- feature_name
str|None(default:None) Base name of feature in resulting feature values
dict.- kwargs
Any Keyword arguments for
func. 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.
- func
- Returns:
dict[str,Any] – 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)