Add border discount for non-rigid warp fields - #543
RichieHakim wants to merge 1 commit into
Conversation
Blend non-rigid registration toward geometric-only registration near FOV borders using a raised-cosine transition. Improves robustness of ROI alignment at image edges where optical flow is unreliable. New parameter: alignment.fit_nonrigid.border_discount_width (default: 50px) Set to 0 to disable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28ec8dd572
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| remappingIdx_blended (np.ndarray): | ||
| Blended remapping indices. Shape *(N, H, W, 2)*. | ||
| """ | ||
| assert remappingIdx_geo.shape == remappingIdx_nonrigid.shape |
There was a problem hiding this comment.
Handle list remapping indices in border-discount helper
pipeline_tracking passes aligner.remappingIdx_geo and aligner.remappingIdx_nonrigid directly into discount_edge_nonrigid, but those fields are built as Python lists of (H, W, 2) arrays in Aligner.fit_geometric/fit_nonrigid (roicat/tracking/alignment.py), while this helper immediately dereferences .shape as if the input were a 4-D ndarray. With nonrigid alignment enabled and border_discount_width > 0 (default is 50), this now raises AttributeError: 'list' object has no attribute 'shape' and breaks the tracking pipeline.
Useful? React with 👍 / 👎.
| aligner.transform_images_nonrigid(FOV_images); | ||
|
|
||
| ## Discount non-rigid warp at FOV borders | ||
| if border_width > 0: | ||
| aligner.remappingIdx_nonrigid = helpers.discount_edge_nonrigid( |
There was a problem hiding this comment.
Recompute nonrigid images after mutating warp field
The pipeline computes ims_registered_nonrigid before applying border discount, then overwrites aligner.remappingIdx_nonrigid with the discounted warp and uses that for ROI transforms. This leaves ims_registered_nonrigid (later exported/visualized) inconsistent with the stored nonrigid remapping and aligned ROIs whenever border_discount_width > 0, so diagnostics and serialized run_data['aligner'] no longer describe the same transform.
Useful? React with 👍 / 👎.
Summary
New parameter:
alignment.fit_nonrigid.border_discount_width(default: 50px)border_widthpixels inward: warp = full non-rigidHow it works:
result = geo + weight * (nonrigid - geo)Files changed
roicat/helpers.py— newdiscount_edge_nonrigid()function (+59 lines)roicat/pipelines.py— pipeline integration (+15 lines)roicat/util.py— new default parameter (+2 lines)tests/test_unit.py— 5 unit tests (+58 lines)Test plan
test_identity_at_zero_border— border_width=0 returns nonrigid unchangedtest_border_equals_geo— edge pixels match geometric warptest_interior_equals_nonrigid— interior pixels match nonrigid warptest_smooth_transition— monotonic increase from edge inwardtest_output_shape— output shape matches input🤖 Generated with Claude Code