Chapter 3 Image segmentation
3.1 Overview
The Visium platform from 10x Genomics has four tissue capture areas.
While 10x Genomics will provide the Visium slide, you can use many different imaging scopes to obtain bright field and/or fluorescent images for regular Visium or Visium immunofluorescence (IF), respectively.
As we will learn in the next chapters, we will want to use Loupe Browser to manually align each tissue capture area prior to running Space Ranger for processing the gene expression data.
You likely will image a full Visium slide with four tissue capture areas. So before you can proceed, you will need to use some external software to split your image into individual capture areas. One such utility is VistoSeg
, which we will illustrate in this chapter.
3.2 What is VistoSeg?
VistoSeg
is a MATLAB pipeline used to process, analyze, and interactively visualize the high-resolution histology images from the 10x Genomics Visium experiment (Tippani et al. (2022)). One of the outputs from VistoSeg
is the estimated number of cells per spot, which can be used as an input in downstream analyses. VistoSeg
can also be used prior to running Loupe
as it can help create high resolution images for each Visium capture area. The main steps in VistoSeg
are as follows:
- Split Image: This step is used to split the large Visium histology whole slide image into individual capture areas, creating four individual
.tif
files. These images can then be used with Loupe Browser. - Nuclei Segmentation: This is a two-step process where nuclei segmentation is performed for images. Nuclei segmentation is followed by a refining step to get a cleaner image of the nuclei segmentation.
- Space Ranger: Next, you need to run
spaceranger count
, described in the Space Ranger chapter, to create the input files for the finalVistoSeg
step. - Count Cells/Nuclei: This step is performed to get the count of cells/nuclei per Visium spot for each capture area.
For more information about VistoSeg
please see its documentation website.
3.3 Split histology images
VistoSeg
provides a MATLAB function called splitSlide
that can take an image with four capture areas and divide this into four images with approximately the same dimensions (they can be a few pixels off in the x-axis). Sometimes the center of the image is not the center of the slide, in which case the offset can be adjusted manually.
Example images for trying out splitSplide
and the corresponding code are available from the VistoSeg
documentation website.
3.3.1 File size issues
As noted on the VistoSeg
software requirements page, high-quality images for a full Visium slide can be as large as ~25 GB each. This means that you will need plenty of memory in order to load the full Visium slide image into MATLAB before you can run splitSlide
. This could be two or three times the amount of the image size on disk. Once you have run splitSlide
, the rest of the VistoSeg
pipeline can run on a machine with 16 GB of RAM (or even less).
3.4 Segment cell nuclei
Once you have run the splitSlide
function from VistoSeg
, you can now proceed to segment the images. This process helps remove background noise in the images so you can more readily identify the cells or nuclei in your bright field image. For fluorescent images, dotdotdot
’s utilities (Maynard et al. (2020)) could potentially be useful, particularly if your images have Z-stacks.
VistoSeg
provides two functions: VNS
(Visium Nuclei Segmentation) and refineVNS
which are used to perform the cell/nuclei segmentation on regular bright field images. This process involves choosing the total number of visually distinguishable colors in the image (5 in our sample image) and running MATLAB’s color-based segmentation using k-means clustering.
For more information and a detailed example check the VistoSeg
documentation website.
3.5 Identify number of cells per spot
VistoSeg
has two utilities for estimating the number of cells per spot. As noted above, for this step you first need to also run Loupe Browser and Space Ranger to generate the Space Ranger output files, which are required here as an input.
The alignment of the individual tissue capture areas with Loupe Browser
is required to identify the centers of each of the Visium spots and their coordinates in the images. As long as all downstream segmented images use the exact same proportions as the input image for Loupe Browser
, we can compute a scaling factor and use it for computing the coordinates of the Visium spots in the new images. Space Ranger
will then provide us the spot coordinate file as well as process the gene expression data. The spot coordinate files will enable us to estimate the number of cells per spot with VistoSeg
, as shown in the Space Ranger chapter.
3.6 Wrapping up
In this chapter we learned about image processing steps required to work with the images we generate as part of our Visium experiments. Given the broad spectrum of imaging scopes, these tools are not available directly within the software provided by 10x Genomics. VistoSeg
can help us split our images and process them so that we can estimate the number of cells or nuclei per Visium spot, which we can then use as an input during downstream analyses.