Skip to content

Support a single nonrigid block along a dimension - #1260

Open
adityasingh2400 wants to merge 1 commit into
MouseLand:mainfrom
adityasingh2400:fix-nonrigid-single-block
Open

Support a single nonrigid block along a dimension#1260
adityasingh2400 wants to merge 1 commit into
MouseLand:mainfrom
adityasingh2400:fix-nonrigid-single-block

Conversation

@adityasingh2400

Copy link
Copy Markdown

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 inside nonrigid.transform_data with RuntimeError: 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_nblocks deliberately returns a single block when the requested block size is at least as large as the dimension, so nblocks can legitimately be [3, 1]. transform_data then computes Lxc = 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, and F.interpolate is 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_left instead of Lx - 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-block transform_data call 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

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.

BUG: Nonrigid registration with a single block along one dimension fails.

1 participant