Skip to content

Add border discount for non-rigid warp fields - #543

Open
RichieHakim wants to merge 1 commit into
devfrom
todo/edge-discount-warps
Open

RichieHakim wants to merge 1 commit into
devfrom
todo/edge-discount-warps

Conversation

@RichieHakim

Copy link
Copy Markdown
Owner

Summary

  • Blend non-rigid registration toward geometric-only registration near FOV borders
  • Uses raised-cosine transition for smooth, derivative-continuous blending
  • Improves robustness of ROI alignment at image edges where optical flow is unreliable

New parameter:

alignment.fit_nonrigid.border_discount_width (default: 50px)

  • At pixel 0 (border): warp = geometric only
  • At border_width pixels inward: warp = full non-rigid
  • Set to 0 to disable (backwards-compatible)

How it works:

  1. Compute distance from nearest FOV border for each pixel
  2. Create weight mask: raised-cosine from 0 (border) to 1 (interior)
  3. Blend: result = geo + weight * (nonrigid - geo)

Files changed

  • roicat/helpers.py — new discount_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 unchanged
  • test_border_equals_geo — edge pixels match geometric warp
  • test_interior_equals_nonrigid — interior pixels match nonrigid warp
  • test_smooth_transition — monotonic increase from edge inward
  • test_output_shape — output shape matches input

🤖 Generated with Claude Code

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread roicat/helpers.py
remappingIdx_blended (np.ndarray):
Blended remapping indices. Shape *(N, H, W, 2)*.
"""
assert remappingIdx_geo.shape == remappingIdx_nonrigid.shape

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread roicat/pipelines.py
Comment on lines 164 to +168
aligner.transform_images_nonrigid(FOV_images);

## Discount non-rigid warp at FOV borders
if border_width > 0:
aligner.remappingIdx_nonrigid = helpers.discount_edge_nonrigid(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

1 participant