Skip to content

fix(annotation): read tiling-preview mask backdrop via reader, not WSI#149

Merged
clemsgrs merged 1 commit into
mainfrom
148-tiling-preview-read-level
Jun 22, 2026
Merged

fix(annotation): read tiling-preview mask backdrop via reader, not WSI#149
clemsgrs merged 1 commit into
mainfrom
148-tiling-preview-read-level

Conversation

@clemsgrs

Copy link
Copy Markdown
Owner

Summary

Annotation-aware tiling previews crashed on every real-slide run with 'WSI' object has no attribute 'read_level', so no preview/tiling/ JPEG was ever produced (the mask preview rendered fine). write_coordinate_preview built the mask backdrop as a WSI and passed it into draw_grid_from_coordinatesread_aligned_mask, which calls mask_obj.read_level(...)/mask_obj.spacings — reader/backend methods that a WSI does not expose. Introduced by #147.

Fix

Pass the backend reader (WSI(...).reader) into the grid renderer's mask-overlay path, mirroring the mask-preview path (overlay_mask_on_slide already uses mask_obj=mask_object.reader). The reader exposes read_level/spacings/level_downsamples, satisfying read_aligned_mask's contract. One-line behavioral change in write_coordinate_preview.

Regression test

tests/test_tiling_preview_mask_overlay.py drives the real openslide-backed fixture slide (tests/fixtures/input/test-wsi.tif) with a derived multi-label pyramidal mask (tumor=1 / stroma=2, split from test-mask.tif) through tile_slides with save_tiling_preview enabled, in both PER_ANNOTATION and SINGLE_OUTPUT modes, asserting a preview/tiling/*.jpg is actually written and the mask preview still renders. It fails on main (reproducing the crash) and passes after the fix. Wired into the CI integration step (pr-test.yaml).

The pre-existing test_overlay_semantics.py fake was the exact "fake WSI that exposes read_level" pattern that hid this bug; its fake now exposes read_level/spacings only on .reader, so a reader-less fake can no longer mask the gap.

Acceptance criteria

  • Annotation tiling previews render on a real (openslide-backed) slide in both PER_ANNOTATION and SINGLE_OUTPUT modes — a JPEG is written under preview/tiling/ mirroring each coordinate artifact path.
  • No read_level AttributeError; the mask backdrop is read via a reader, not a WSI.
  • Mask-preview behavior is unchanged (still rendered).
  • A regression test exercises the tiling-preview mask-overlay branch against a real backend whose WSI does NOT expose read_level; it fails on current main and passes after the fix.

Test result

Full default fast suite: 289 passed, 3 skipped, 46 deselected. Integration set (incl. new test): 6 passed.

Closes #148

🤖 Generated with Claude Code

Annotation tiling previews crashed on every real-slide run with
'WSI' object has no attribute 'read_level', so no preview/tiling JPEG
was produced. write_coordinate_preview built the mask backdrop as a
WSI and handed it to draw_grid_from_coordinates -> read_aligned_mask,
which calls read_level/spacings -- reader/backend methods a WSI does
not expose. Pass the reader (mirroring overlay_mask_on_slide's
mask_obj=mask_object.reader), closing the WSI-vs-reader gap.

Add an integration regression that drives the real openslide-backed
fixture slide through tile_slides with a multi-label mask and
save_tiling_preview in both PER_ANNOTATION and SINGLE_OUTPUT modes,
asserting a preview/tiling/*.jpg is actually written. It fails on
main (reproducing the crash) and passes after the fix. Wire it into
the CI integration step. Update the overlay-semantics fake so the
mask exposes read_level only on .reader (not on the WSI), so a
reader-less fake can no longer hide this gap.

Closes #148

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clemsgrs
clemsgrs merged commit 9dca279 into main Jun 22, 2026
1 check passed
@clemsgrs
clemsgrs deleted the 148-tiling-preview-read-level branch June 22, 2026 15:24
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.

Annotation tiling previews crash on real slides: 'WSI' object has no attribute 'read_level'

1 participant