Chapter 3 Image segmentation

3.1 Overview

The Visium platform from 10x Genomics has four tissue capture areas.

Visium slide design. Source: [10x Genomics](https://kb.10xgenomics.com/hc/en-us/articles/360035487572-What-is-the-spatial-resolution-and-configuration-of-the-capture-area-of-the-Visium-Gene-Expression-Slide-).

Figure 3.1: Visium slide design. Source: 10x Genomics.

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.

Visium images you might generate using your preferred imaging scope: bright field images showing the tissue or multi-channel fluorescent images. Source: [10x Genomics](https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/using/input-recommendations).

Figure 3.2: Visium images you might generate using your preferred imaging scope: bright field images showing the tissue or multi-channel fluorescent images. Source: 10x Genomics.

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.

A single Visium tissue capture area with the fiducial frame aligned through the Loupe Browser such that the red circles overlap the fiducial frame as determined by visual inspection. Source: [10x Genomics](https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/images).

Figure 3.3: A single Visium tissue capture area with the fiducial frame aligned through the Loupe Browser such that the red circles overlap the fiducial frame as determined by visual inspection. Source: 10x Genomics.

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 final VistoSeg step.
  • Count Cells/Nuclei: This step is performed to get the count of cells/nuclei per Visium spot for each capture area.
`VistoSeg` pipeline overview. Source: [`VistoSeg`](http://research.libd.org/VistoSeg/index.html#why-spatial-transcriptomics-or-visium-imaging).

Figure 3.4: VistoSeg pipeline overview. Source: VistoSeg.

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.

An example bright field image with four Visium tissue capture areas. Source: [`VistoSeg`](http://research.libd.org/VistoSeg/step-1-split-visium-histology-whole-slide-image-into-individual-capture-area-images.html).

Figure 3.5: An example bright field image with four Visium tissue capture areas. Source: VistoSeg.

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.

`dotdotdot` overview figure. Notice the Z-stacked images which some scopes produce. Source: [`dotdotdot`](https://doi.org/10.1093/nar/gkaa312).

Figure 3.6: dotdotdot overview figure. Notice the Z-stacked images which some scopes produce. Source: dotdotdot.

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.

Color cluster 3 is the one that best corresponds to the nuclei for an example capture area image shown in the `VistoSeg` documentation. Pixels corresponding to this cluster are shown in gray and the remaining background pixels in green. Source: [`VistoSeg`](http://research.libd.org/VistoSeg/step-1-split-visium-histology-whole-slide-image-into-individual-capture-area-images.html).

Figure 3.7: Color cluster 3 is the one that best corresponds to the nuclei for an example capture area image shown in the VistoSeg documentation. Pixels corresponding to this cluster are shown in gray and the remaining background pixels in green. Source: VistoSeg.

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.