Skip to content

Updates stitcher to trim all edges evenly rather than right/bottom only.#24

Merged
k-rl merged 2 commits intomainfrom
stitcher_update
Jun 2, 2025
Merged

Updates stitcher to trim all edges evenly rather than right/bottom only.#24
k-rl merged 2 commits intomainfrom
stitcher_update

Conversation

@palmhjell
Copy link
Copy Markdown
Contributor

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:
Screenshot 2025-05-30 at 4 57 26 PM

Adjusting the trimming operation to trim each edge of the image symmetrically gives much better images:
Screenshot 2025-06-02 at 11 31 17 AM

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

Copy link
Copy Markdown
Collaborator

@k-rl k-rl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good just one small comment + fixing the ruff issues and we're good to merge :)

: assay.tile.shape[-1] - self.overlap,
]
# Only clip if overlap is non-zero
if self.overlap > 0:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@k-rl k-rl merged commit ca8a9cd into main Jun 2, 2025
20 checks passed
@palmhjell palmhjell deleted the stitcher_update branch June 2, 2025 20:05
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.

2 participants