%matplotlib inline

Show layers of the ImageContainer

This example shows how to use squidpy.im.ImageContainer.show().

This function is useful to visualize statically different layers of the squidpy.im.ImageContainer class.

See also

import squidpy as sq

Load the Mibitof dataset.

adata = sq.datasets.mibitof()

We can briefly visualize the data to understand the type of images we have.

sq.pl.spatial_segment(
    adata,
    library_id=["point16", "point23", "point8"],
    seg_cell_id="cell_id",
    color="Cluster",
    library_key="library_id",
    title=["point16", "point23", "point8"],
)
../../../_images/f42e5ef7dc7afed90e6cce5930c9438954f91b9637dca2bff1417b332ea630b6.png

We have three different tissue samples. We also have segmentation masks for each tissue sample. Let’s extract the image from the anndata.AnnData object and create a squidpy.im.ImageContainer object.

imgs = []
for library_id in adata.uns["spatial"].keys():
    img = sq.im.ImageContainer(
        adata.uns["spatial"][library_id]["images"]["hires"], library_id=library_id
    )
    img.add_img(
        adata.uns["spatial"][library_id]["images"]["segmentation"],
        library_id=library_id,
        layer="segmentation",
    )
    img["segmentation"].attrs["segmentation"] = True
    imgs.append(img)
img = sq.im.ImageContainer.concat(imgs)
WARNING: Channel dimension cannot be aligned with an existing one, using `channels_0`
WARNING: Channel dimension cannot be aligned with an existing one, using `channels_0`
WARNING: Channel dimension cannot be aligned with an existing one, using `channels_0`

We can visualize each image of the object with squidpy.im.ImageContainer.show().

img.show("image")
../../../_images/a6fd222583b4b77447d213c029732e28097666dd7c00d60c1d97f0662521cecf.png

squidpy.im.ImageContainer.show() also allows to overlay the results of segmentation.

img.show("image", segmentation_layer="segmentation", segmentation_alpha=0.5)
../../../_images/24f00c0e4055df5d6a3192d635e815e589c6b1580e97c29e9f9eda4c9d3d1ad4.png