Launch binder

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()

Out:

  0%|          | 0.00/19.3M [00:00<?, ?B/s]
  0%|          | 56.0k/19.3M [00:00<00:47, 430kB/s]
  1%|          | 160k/19.3M [00:00<00:31, 639kB/s]
  3%|3         | 616k/19.3M [00:00<00:10, 1.92MB/s]
 12%|#2        | 2.37M/19.3M [00:00<00:02, 6.56MB/s]
 39%|###9      | 7.59M/19.3M [00:00<00:00, 18.7MB/s]
 69%|######8   | 13.3M/19.3M [00:00<00:00, 27.3MB/s]
 98%|#########8| 19.0M/19.3M [00:00<00:00, 32.8MB/s]
100%|##########| 19.3M/19.3M [00:00<00:00, 21.2MB/s]

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"],
)
point16, point23, point8

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)

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

img.show("image")
image, library_id:point16, image, library_id:point23, image, library_id:point8

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

img.show("image", segmentation_layer="segmentation", segmentation_alpha=0.5)
image, library_id:point16, image, library_id:point23, image, library_id:point8

Total running time of the script: ( 0 minutes 24.429 seconds)

Estimated memory usage: 370 MB