Updates stitcher to trim all edges evenly rather than right/bottom only.#24
Merged
Updates stitcher to trim all edges evenly rather than right/bottom only.#24
Conversation
k-rl
requested changes
Jun 2, 2025
Collaborator
k-rl
left a comment
There was a problem hiding this comment.
Looks good just one small comment + fixing the ruff issues and we're good to merge :)
src/magnify/stitch.py
Outdated
| : assay.tile.shape[-1] - self.overlap, | ||
| ] | ||
| # Only clip if overlap is non-zero | ||
| if self.overlap > 0: |
Collaborator
There was a problem hiding this comment.
Rather than checking for this condition could you do the same thing I did in the previous version of the code which is to just have:
tiles = assay.tile[
...,
clip : assay.tile.shape[-2] - clip + remainder,
clip : assay.tile.shape[-1] - clip + remainder,
]That way you're minimizing how much branching happens in the code which makes it easier to reason about. If you're concerned about a bug being introduced later on when the code gets changed because of the tricky indexing you can leave a comment explaining that we're intentionally not using the negative endpoint indexing here because of when self. overlap is 0.
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.
The stitcher currently trims each tile by adjusting the size of the image (e.g.,
tile.shape[-1] - overlap) which only cuts off one side of each tile rather than trimming it symmetrically. When the image has some vignetting or other artifacts on the edges, these would get carried over to each tile rather than being trimmed evenly and interfere with the chamber images.For example, residual darkness from the neutral density filter on Setup 7 (which annoyingly remains even when the filter is fully open) is retained at the top of each chamber here and effectively cuts many chambers in half across full rows:

Adjusting the trimming operation to trim each edge of the image symmetrically gives much better images:

This PR implements this fix and handles
overlapvalues that are 0 or odd.