feat(stitch): add normalize_mosaic — averaging companion to the accumulators#11
Merged
Merged
Conversation
…ccumulators The stitch_batch_* accumulators deliberately leave normalization to the caller. normalize_mosaic completes that API: given a (canvas, counts) pair it returns (fill_value, mosaic) where covered pixels (counts >= min_overlap) become canvas/counts, under-covered pixels become NaN, and fill_value is the median of covered pixels (a neutral background for renderers that treat NaN as zero). Lifted from holoptycho/vit_inference.py MosaicWriterOp._normalise_full so holoptycho can import it instead of carrying the inline copy. Tested in tests/test_stitch.py (averaging, NaN masking, fill=median, inclusive threshold, higher-threshold exclusion, empty input, float32 output, input immutability, and an end-to-end stitch->normalize round-trip). Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
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.
Adds
normalize_mosaic(canvas, counts, min_overlap=0.5)toptychoml.stitch.Why
The
stitch_batch_*accumulators deliberately leave normalization to the caller (their docstrings say "No normalization happens here").normalize_mosaicis the missing other half of that API — it averages a(canvas, counts)pair into a display mosaic:counts >= min_overlap) →canvas / countsNaN(fill_value, mosaic)wherefill_valueis the median of covered pixels — a neutral background for renderers that treatNaNas zeroLifted from
holoptycho/vit_inference.py'sMosaicWriterOp._normalise_fullso holoptycho can import it instead of carrying the inline copy (a follow-up updates the H3 PR NSLS2/holoptycho#40 to use it).Tests
tests/test_stitch.py(+9 cases): averaging, NaN masking of thin coverage,fill_value == median(covered), inclusive threshold boundary, higher-threshold exclusion, empty input →(0.0, all-NaN), float32 output, input immutability, and an end-to-endstitch_batch_livestitch_into → normalize_mosaicround-trip that recovers the patch value.Docs
README Stitching table + usage example updated to use
normalize_mosaic; AGENTS.md note added.