Support a single nonrigid block along a dimension - #1260
Open
adityasingh2400 wants to merge 1 commit into
Open
Conversation
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.
Nonrigid registration crashes when the block size spans a whole dimension of the frame, for example
block_size = [64, 256]on a 256 by 256 movie. It fails insidenonrigid.transform_datawithRuntimeError: Input and output sizes should be greater than 0, but got input (H: 3, W: 1) output (H: 64, W: 0).The cause is the interpolation target size.
calculate_nblocksdeliberately returns a single block when the requested block size is at least as large as the dimension, sonblockscan legitimately be[3, 1].transform_datathen computesLxc = xb.max() - xb.min(), which is the span between the first and last block centre. With one block along x every centre coincides, that span is zero, andF.interpolateis asked for an output of width zero. So the configuration the block code is designed to produce is one the shift code cannot consume.The fix clamps the interpolation size to at least one pixel and derives the trailing pad from that size rather than from the block centre,
Lx - Lxc - pad_leftinstead ofLx - xb.max(). A single block now interpolates onto one pixel and the existing replicate padding broadcasts that one shift across the full dimension, which is the correct semantics since one block means one shift everywhere. The two forms of the trailing pad are algebraically equal whenever there are two or more blocks, so the multi-block path is untouched. I confirmed that directly: a multi-blocktransform_datacall produces bit-identical output before and after the change.Tested with new cases in
tests/test_registration.py. Three parametrised cases cover a single block along y, along x, and along both, and a fourth asserts that a single block and a multi-block grid produce identical output when every block carries the same shift, which pins down the padding arithmetic rather than just the absence of a crash. All four fail on main with the RuntimeError above and pass with this change, and the existing tests in the file still pass, 7 passed in total.Fixes #1211