<jupyter_start><jupyter_text>Extract segmentation features=============================This example shows how to extract segmentation features from the tissueimage.Features extracted from a nucleus segmentation range from the number ofnuclei per image, over nuclei shapes and sizes, to the intensity of theinput channels within the segmented objects. They are very interpretablefeatures and provide valuable additional information. Segmentationfeatures are calculated by using `features = 'segmentation'`, whichcalls `squidpy.im.ImageContainer.features_segmentation`.In addition to `feature_name` and `channels` we can specify thefollowing `features_kwargs`:-   `label_layer` - name of label image layer in `img`.-   `props` - segmentation features that are calculated. See    [properties]{.title-ref} in `skimage.measure.regionprops_table`.::: {.seealso}-   `sphx_glr_auto_examples_image_compute_segment_fluo.py` for more    details on calculating a cell-segmentation.-   `sphx_glr_auto_examples_image_compute_features.py` for the general    usage of `squidpy.im.calculate_image_features`.:::<jupyter_code>import scanpy as sc
import squidpy as sq

import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>First, let\'s load the fluorescence Visium dataset.<jupyter_code>img = sq.datasets.visium_fluo_image_crop()
adata = sq.datasets.visium_fluo_adata_crop()<jupyter_output><empty_output><jupyter_text>Before calculating segmentation features, we need to first calculate asegmentation using `squidpy.im.segment`.<jupyter_code>sq.im.segment(img=img, layer="image", layer_added="segmented_watershed", method="watershed", channel=0)<jupyter_output><empty_output><jupyter_text>Now we can calculate segmentation features. Here, we will calculate thefollowing features:> -   number of nuclei `label`.> -   mean area of nuclei `area`.> -   mean intensity of channels 1 (anti-NEUN) and 2 (anti-GFAP) within>     nuclei `mean_intensity`.We use `mask_cicle = True` to ensure that we are only extractingfeatures from the tissue underneath each Visium spot. For more detailson the image cropping, see`sphx_glr_auto_examples_image_compute_crops.py`.<jupyter_code>sq.im.calculate_image_features(
    adata,
    img,
    layer="image",
    features="segmentation",
    key_added="segmentation_features",
    features_kwargs={
        "segmentation": {
            "label_layer": "segmented_watershed",
            "props": ["label", "area", "mean_intensity"],
            "channels": [1, 2],
        }
    },
    mask_circle=True,
)<jupyter_output><empty_output><jupyter_text>The result is stored in `adata.obsm['segmentation_features']`.<jupyter_code>adata.obsm["segmentation_features"].head()<jupyter_output><empty_output><jupyter_text>Use `squidpy.pl.extract` to plot the texture features on the tissueimage or have a look at [our interactive visualizationtutorial](../../external_tutorials/tutorial_napari.ipynb) to learn howto use our interactive `napari` plugin. Here, we show all calculatedsegmentation features.<jupyter_code># show all channels (using low-res image contained in adata to save memory)
fig, axes = plt.subplots(1, 3, figsize=(8, 4))
for i, ax in enumerate(axes):
    ax.imshow(adata.uns["spatial"]["V1_Adult_Mouse_Brain_Coronal_Section_2"]["images"]["hires"][:, :, i])
    ax.set_title(f"ch{i}")

# plot segmentation features
sc.pl.spatial(
    sq.pl.extract(adata, "segmentation_features"),
    color=[
        "segmentation_label",
        "segmentation_area_mean",
        "segmentation_ch-1_mean_intensity_mean",
        "segmentation_ch-2_mean_intensity_mean",
    ],
    bw=True,
    ncols=2,
    vmin="p1",
    vmax="p99",
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11174396528342827, 'fraction_numerical': 0.004610794684024953, 'mean_word_length': 5.504409171075838, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '323787', 'license': 'MIT', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1120, 'n_words': 289, 'path': 'docs/source/auto_examples/image/compute_segmentation_features.ipynb', 'repo_name': 'theislab/squidpy_notebooks', 'size': '3687'}