assign_stitch_groups#
- squidpy.experimental.tl.assign_stitch_groups(sdata, *, labels_key, qc_table_key=None, min_confidence=0.7, max_gap=3.0, max_group_size=4, inplace=True, distance_tol=0.75, min_edge_length=5.0, min_edge_length_ratio=0.4, min_edge_coverage=0.5, candidate_min_iou=0.2, close_radius=3)[source]#
Assign tile-cut cell pieces to stitch groups.
Reads
is_outlier=Truecells flagged bycalculate_tiling_qc(), pairs facing cut edges across tile boundaries, scores each pair via a transparent geometric composite, and assembles high-confidence pairs into stitch groups via union-find. This only annotates which pieces belong together – it does not modify the labels element. Materialising a stitched labels element is opt-in viamake_stitched_labels().The score per pair is the flat (unweighted) mean of five geometric features in [0, 1]:
iou(1-D extent overlap),endpoint_match(chord endpoints coincide),merge_compactness(4*pi*A / P^2of the closed union mask),merge_solidity(union area / convex hull area), andgap_proximity(seam gap relative to the morphological closing reach). No coefficients are fitted or shipped; the features are recorded in.uns["tiling_stitch"].- Parameters:
- sdata
SpatialData SpatialDatawith a labels element and a QC table fromcalculate_tiling_qc().- labels_key
str Key in
sdata.labels.- qc_table_key
str|None(default:None) Key of the QC table. If
None,f"{labels_key}_qc".- min_confidence
float(default:0.7) Threshold on
stitch_confidence.0.7is a starting point; raise it for stricter precision, lower for recall. Tune for your data – the score is heuristic, not a calibrated probability.- max_gap
float(default:3.0) Maximum perpendicular distance (px) between facing cut edges for a pair to be considered a candidate. This is a search radius only; it does not scale the score.
- max_group_size
int(default:4) Cap on group size; oversized groups (likely false merges) collapse to singletons.
- inplace
bool(default:True) If
True, write back intosdata.tables[qc_table_key]. Otherwise return the modified AnnData.- distance_tol
float(default:0.75) Sub-pixel tolerance for “lies on a bbox edge”.
- min_edge_length
float(default:5.0) Absolute floor on cut-edge length (pixels).
- min_edge_length_ratio
float(default:0.4) Minimum cut-edge length relative to the cell’s equivalent diameter.
- min_edge_coverage
float(default:0.5) Minimum fraction of parallel-axis positions covered by near-edge contour points.
- candidate_min_iou
float(default:0.2) Loose 1-D IoU floor at candidate enumeration.
- close_radius
int(default:3) Morphological closing disk radius for the union mask. Also the length scale for
gap_proximity(normalised by2 * close_radius).
- sdata
- Returns:
AnnData|None– The QCAnnDatawith four new.obscolumns wheninplace=False, otherwiseNone.