Skip to content

Add tiling QC metric for tile-boundary segmentation artifacts#1156

Closed
timtreis wants to merge 1 commit into
feature/add_cpmeasurefrom
feature/tiling-qc
Closed

Add tiling QC metric for tile-boundary segmentation artifacts#1156
timtreis wants to merge 1 commit into
feature/add_cpmeasurefrom
feature/tiling-qc

Conversation

@timtreis

Copy link
Copy Markdown
Member

Summary

  • Adds sq.experimental.tl.calculate_tiling_qc — per-cell scoring that detects cells artificially cut by tile boundaries during segmentation, using collinearity-based straight-edge detection on contours
  • Adds sq.experimental.pl.tiling_qc — diagnostic plot via spatialdata-plot where the tile grid emerges from high-scoring cells without requiring tile-border metadata
  • Scores stored in .obs of a QC AnnData table ({labels_key}_qc) with proper spatialdata_attrs linking and algorithm params in .uns["tiling_qc"]
  • Scales to 100k×100k images via the tiling infrastructure from [EXPERIMENTAL]: Integrate cp-measure #982 (labels-only tile extraction, centroids computed without materialising full arrays)

Metrics

Metric Description
max_straight_edge_ratio Longest collinear boundary segment / equivalent diameter
cardinal_alignment_score Axis-alignment of that segment (1 = cardinal, 0 = diagonal)
cut_score Product of the two

Test plan

  • 27 unit tests for geometry helpers, per-tile scoring, and edge cases
  • 8 integration tests (end-to-end with fixture, tiled vs single-tile equivalence, spatialdata attrs, params in uns, centroids in obs)
  • 2 visual regression tests via PlotTester

🤖 Generated with Claude Code

Cells segmented in tiles get cut at tile borders, producing fragments
with artificially straight edges. This adds:

- `sq.experimental.tl.calculate_tiling_qc`: per-cell scoring via
  collinearity-based straight-edge detection (max_straight_edge_ratio,
  cardinal_alignment_score, cut_score). Scores stored in .obs of a
  QC AnnData table linked to the labels element via spatialdata_attrs.
  Algorithm parameters recorded in .uns["tiling_qc"].
- `sq.experimental.pl.tiling_qc`: diagnostic plot via spatialdata-plot
  (renders labels coloured by score; tile grid emerges from the data).
- `extract_labels_tile_lazy` in _tiling.py for labels-only tile
  extraction without materialising an image.
- Test fixture with 400x400 dask-backed ellipsoid cells cut by a
  3x3 tile grid, with ground-truth cut/intact classification.
- 35 tests (unit, integration, visual regression).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@timtreis timtreis closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant