In [ ]:
%matplotlib inline


# Extract histogram features¶

This example shows how to extract histogram features from tissue image.

Histogram features give a more detailed view than summary features (sphx_glr_auto_examples_image_compute_summary_features.py) by computing a histogram of each image channel and returning bin-counts for each Visium spot.

In addition to feature_name and channels we can specify the following features_kwargs:

• bins - number of bins of the histogram, default is 10.
• v_range - range on which values are binned, default is the whole image range.

::: seealso See sphx_glr_auto_examples_image_compute_features.py for general usage of squidpy.im.calculate_image_features. :::

In [ ]:
import squidpy as sq


Lets load the fluorescence Visium dataset and calculate bin-counts (3 bins) of channels 0 and 1.

In [ ]:
# get spatial dataset including high-resolution tissue image
img = sq.datasets.visium_fluo_image_crop()

# calculate histogram features and save in key "histogram_features"
sq.im.calculate_image_features(
img,
features="histogram",
features_kwargs={"histogram": {"bins": 3, "channels": [0, 1]}},
)


The result is stored in adata.obsm['histogram_features'].

In [ ]:
adata.obsm["histogram_features"].head()


Use squidpy.pl.extract to plot the histogram features on the tissue image or have a look at our interactive visualisation tutorial to learn how to use our interactive napari plugin. With these features we can e.g. appreciate the detailed distribution of intensity values of channel 0 (DAPI stain) on the different bins.

In [ ]:
sq.pl.spatial_scatter(