Skip to content

bidiphase.shift: copy the source slice before the overlapping in-place assignment - #1266

Open
cindykrafft wants to merge 1 commit into
MouseLand:mainfrom
cindykrafft:fix/bidiphase-torch-overlap
Open

cindykrafft wants to merge 1 commit into
MouseLand:mainfrom
cindykrafft:fix/bidiphase-torch-overlap

Conversation

@cindykrafft

Copy link
Copy Markdown

Fixes #1265.

bidiphase.shift shifts the odd scan lines with an in-place assignment whose source and destination slices overlap. numpy handles that with a temporary copy; torch.Tensor.copy_ does not, so since the registration path started passing torch tensors (v1.0.0.1) every odd line was corrupted instead of shifted (with bidiphase=3, 34 % of odd-line pixels in register_frames' output differ from the intended shift), while the reference image — still shifted through the numpy path in registration_wrapper — was correct.

This copies the source slice first (clone() for torch, copy() for numpy), restoring the numpy semantics for both array types. Verified on 1.1.0 + this patch: register_frames(..., bidiphase=3) reproduces the numpy result exactly, for positive and negative offsets.

🤖 Generated with Claude Code

https://claude.ai/code/session_012d2sJAD5EUp4GqAStqoBX7

…e assignment

bidiphase.shift shifts the odd scan lines with an in-place assignment whose
source and destination slices overlap. numpy handles overlapping assignments
by making a temporary copy, but torch.Tensor.copy_ does not, so since the
registration path started passing torch tensors (v1.0.0.1) every odd line
was corrupted instead of shifted: with bidiphase=3, 34% of odd-line pixels
in register_frames' output differ from the intended shift (they contain
repeated copies of the first columns). The reference image, which still
goes through the numpy path in registration_wrapper, was shifted correctly,
so frames and reference disagreed.

Copy the source slice first (clone for torch, copy for numpy), which
restores the numpy semantics for both array types.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012d2sJAD5EUp4GqAStqoBX7

This branch has not been deployed

No deployments
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: bidiphase correction corrupts odd scan lines since the torch registration path (v1.0.0.1)

2 participants