Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Sopa: tiled segmentation

What it does

Sopa cuts the image into overlapping square patches, segments each patch separately, and then joins the results, merging cells found twice where patches overlap. This lets any image size be segmented, many patches at a time.

Parameters

How it works

Segmentation models need a lot of memory on large images. Sopa therefore segments small patches that overlap, and turns each patch’s masks into polygons. The overlap should be at least twice the average cell diameter, so that every cell lies whole in at least one patch Blampey et al., 2024.

A cell in an overlap is found twice, once by each patch. When two outlines share at least half the area of the smaller one, they are replaced by their union; otherwise both are kept. In the Sopa paper such conflicts were rare (0.007 % of Cellpose cell pairs) and patching did not measurably change segmentation quality.

Two overlapping patches with cells; one cell in the overlap is outlined by both patches, and after resolving it is a single merged outline.

Two overlapping patches. Each finds the cells inside it; the cell in the overlap is found by both, and resolving merges the two outlines into one.

In this pipeline, in order:

  1. Tissue (optional). With use_tissue_segmentation, the tissue is outlined on a coarse level of the image: the brightest channel at each pixel (or the one you name) is thresholded with Otsu’s method. Patches are clipped to the outline, and patches without tissue are dropped.

  2. Patches. One grid per sample, shared by every method and target.

  3. Segmentation. Each patch is segmented by Cellpose or InstanSeg, for cells, nuclei or both, each patch as its own cluster job.

  4. Joining. The patches of one segmentation are joined in a fixed order, overlaps resolved, and the cells numbered, so a rerun gives the same ids.

A sample with no patches, or a segmentation that finds no cells, stops the run and names it.

Inputs and outputs. In: the image in the SpatialData store. Out: the patch grid (image_patches), the tissue outline (region_of_interest) when used, and one set of cell polygons per method and target, all in the store. The QC report’s “Cells per patch” map shows the grid; see Reports.

Similar tools

Tiling is the core reason for this pipeline’s design. Inputs range from 5 to 100 GB; with tiling, the memory a job needs follows the patch, not the slide, and patches run in parallel on a cluster.

Read more

Version used:

ModuleToolVersionContainerPaper
MAKE_IMAGE_PATCHESsopa2.2.9community.wave.seqera.io/library/python_sopa:54a97bc5a187152d
TISSUE_SEGMENTATIONsopa2.2.9community.wave.seqera.io/library/python_sopa:54a97bc5a187152d
RESOLVEsopa2.3.0docker.io/josenimo/sopa:2.3.0-1Blampey et al. (2024)
References
  1. Blampey, Q., Mulder, K., Gardet, M., Christodoulidis, S., Dutertre, C.-A., André, F., Ginhoux, F., & Cournède, P.-H. (2024). Sopa: a technology-invariant pipeline for analyses of image-based spatial omics. Nature Communications, 15(1). 10.1038/s41467-024-48981-z