Skip to content

Fix zero-padding edge case in tile stitching - #60

Merged
JLrumberger merged 1 commit into
angelolab:mainfrom
Dartayous:fix-zero-padding-stitch
Jun 3, 2026
Merged

Fix zero-padding edge case in tile stitching#60
JLrumberger merged 1 commit into
angelolab:mainfrom
Dartayous:fix-zero-padding-stitch

Conversation

@Dartayous

Copy link
Copy Markdown
Contributor

What is the purpose of this PR?

This PR fixes a tile-stitching edge case related to issue #59.

When bottom or right padding is 0, the current _stitch_tiles() slicing logic can collapse the stitched output to an empty spatial dimension because Python evaluates -0 as 0.

Closes #59

How did you implement your changes?

Updated Nimbus._stitch_tiles() in src/nimbus_inference/nimbus.py.

The previous implementation used:

stitched[:, :, padding[0] : -padding[1], padding[2] : -padding[3]]

When padding[1] == 0 or padding[3] == 0, this becomes a start:0 slice and can produce an output shape like (1, 1, 0, 0).

The fix explicitly uses None for zero end-padding:

h_end = None if padding[1] == 0 else -padding[1]
w_end = None if padding[3] == 0 else -padding[3]

stitched = stitched[:, :, padding[0]:h_end, padding[2]:w_end]

I also added a regression test, test_stitch_tiles_handles_zero_end_padding, which verifies that zero bottom/right padding preserves the expected stitched output shape.

Validation:

pytest tests/test_nimbus.py -v
7 passed

Remaining issues

None from my testing. I would appreciate maintainer feedback on whether this is the preferred place to handle the zero-padding crop edge case.

@JLrumberger

Copy link
Copy Markdown
Collaborator

Thanks @Dartayous, the code looks good.

@JLrumberger
JLrumberger merged commit 241281e into angelolab:main Jun 3, 2026
12 checks passed
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.

Nimbus tiled inference can produce empty stitched prediction when right/bottom padding is zero

2 participants