fix(annotation): read tiling-preview mask backdrop via reader, not WSI#149
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Annotation-aware tiling previews crashed on every real-slide run with
'WSI' object has no attribute 'read_level', so nopreview/tiling/JPEG was ever produced (the mask preview rendered fine).write_coordinate_previewbuilt the mask backdrop as aWSIand passed it intodraw_grid_from_coordinates→read_aligned_mask, which callsmask_obj.read_level(...)/mask_obj.spacings— reader/backend methods that aWSIdoes 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_slidealready usesmask_obj=mask_object.reader). The reader exposesread_level/spacings/level_downsamples, satisfyingread_aligned_mask's contract. One-line behavioral change inwrite_coordinate_preview.Regression test
tests/test_tiling_preview_mask_overlay.pydrives the real openslide-backed fixture slide (tests/fixtures/input/test-wsi.tif) with a derived multi-label pyramidal mask (tumor=1 / stroma=2, split fromtest-mask.tif) throughtile_slideswithsave_tiling_previewenabled, in bothPER_ANNOTATIONandSINGLE_OUTPUTmodes, asserting apreview/tiling/*.jpgis actually written and the mask preview still renders. It fails onmain(reproducing the crash) and passes after the fix. Wired into the CI integration step (pr-test.yaml).The pre-existing
test_overlay_semantics.pyfake was the exact "fake WSI that exposesread_level" pattern that hid this bug; its fake now exposesread_level/spacingsonly on.reader, so a reader-less fake can no longer mask the gap.Acceptance criteria
PER_ANNOTATIONandSINGLE_OUTPUTmodes — a JPEG is written underpreview/tiling/mirroring each coordinate artifact path.read_levelAttributeError; the mask backdrop is read via a reader, not a WSI.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