Note
Click here to download the full example code
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
See Crop images with ImageContainer and Smooth an image for additional examples on methods of the
squidpy.im.ImageContainer
.
import squidpy as sq
Load the Mibitof dataset.
adata = sq.datasets.mibitof()
Out:
0%| | 0.00/19.3M [00:00<?, ?B/s]
0%| | 24.0k/19.3M [00:00<01:50, 183kB/s]
0%| | 56.0k/19.3M [00:00<01:33, 217kB/s]
1%| | 120k/19.3M [00:00<00:59, 338kB/s]
1%|1 | 256k/19.3M [00:00<00:31, 625kB/s]
3%|2 | 544k/19.3M [00:00<00:16, 1.19MB/s]
6%|5 | 1.10M/19.3M [00:00<00:08, 2.29MB/s]
12%|#1 | 2.23M/19.3M [00:00<00:04, 4.41MB/s]
23%|##3 | 4.50M/19.3M [00:01<00:01, 8.58MB/s]
37%|###6 | 7.09M/19.3M [00:01<00:01, 12.1MB/s]
51%|#####1 | 9.91M/19.3M [00:01<00:00, 15.1MB/s]
65%|######5 | 12.6M/19.3M [00:01<00:00, 16.8MB/s]
80%|######## | 15.5M/19.3M [00:01<00:00, 18.4MB/s]
95%|#########4| 18.3M/19.3M [00:01<00:00, 19.4MB/s]
100%|##########| 19.3M/19.3M [00:01<00:00, 11.4MB/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"],
)

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

squidpy.im.ImageContainer.show()
also allows to overlay the results of segmentation.
img.show("image", segmentation_layer="segmentation", segmentation_alpha=0.5)

Total running time of the script: ( 0 minutes 25.416 seconds)
Estimated memory usage: 330 MB