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¶
patch_width_pixel, default 2000: the side of a patch in pixels. Aim for 16 to 200 patches; see Patch size. Keep it the same when you compare runs, since it changes results at patch borders.patch_overlap_pixel, default 100: about twice a cell diameter.use_tissue_segmentation, withlevel,modeandtissue_segmentation_kwargs: skip patches on empty glass; see Skip empty glass.min_area_pixels2: drop objects smaller than this, in px². Unset, nothing is dropped.
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. 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:
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.Patches. One grid per sample, shared by every method and target.
Segmentation. Each patch is segmented by Cellpose or InstanSeg, for cells, nuclei or both, each patch as its own cluster job.
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¶
Segmenting the whole image at once, as most pipelines do: simpler, but memory grows with the slide, and a 100 GB whole-slide image does not fit.
Cellpose’s own tiling splits the image into tiles too, but inside one program on one machine.
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¶
The Sopa paper, on patches and conflicts: Blampey et al., 2024.
Version used:
| Module | Tool | Version | Container | Paper |
|---|---|---|---|---|
| MAKE_IMAGE_PATCHES | sopa | 2.2.9 | community.wave.seqera.io/library/python_sopa:54a97bc5a187152d | |
| TISSUE_SEGMENTATION | sopa | 2.2.9 | community.wave.seqera.io/library/python_sopa:54a97bc5a187152d | |
| RESOLVE | sopa | 2.3.0 | docker.io/josenimo/sopa:2.3.0-1 | Blampey et al. (2024) |
- 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