Skip to content

FIX: Broken 4D resampling #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2025

Conversation

oesteban
Copy link
Collaborator

@oesteban oesteban commented Jul 18, 2025

Summary

Resolves several issues in 4D transformations, happening both in "serialized" mode (iterating over 3D volumes) as well as "all-at-once" (interpolating on 4D coordinates). The PR was initiated with codex, generating a new test case that reproduced the problem (it's a small image with only one voxel set to 1, and the transform is a translation along the i-axis of 1 voxel per timepoint (i.e., the voxel moves from one extreme to the other along X in space).

Issues found:

  • The serialized mode was not properly initiating the interpolation targets. Their calculation has been made more general and works for both operation modes (serialized, all-at-once).
  • The all-at-once was generating nonsensical targets, reshapings were just fitting the shape of the targets array to what map_coordinates wants, but did not make any sense.

Both issues have been now resolved and the new test exercises both.

Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.81%. Comparing base (82f58c1) to head (4e159c2).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #247      +/-   ##
==========================================
- Coverage   94.88%   94.81%   -0.08%     
==========================================
  Files          16       16              
  Lines        1859     1872      +13     
  Branches      243      242       -1     
==========================================
+ Hits         1764     1775      +11     
- Misses         77       80       +3     
+ Partials       18       17       -1     
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oesteban oesteban changed the title Add failing test for serialized 4D resampling FIX: Broken 4D resampling Jul 18, 2025
@oesteban oesteban force-pushed the codex/investigate-4d-dataset-resampling-issue branch from 6377203 to 4e159c2 Compare July 18, 2025 15:27
@oesteban oesteban merged commit f1efba1 into master Jul 18, 2025
14 of 15 checks passed
@oesteban oesteban deleted the codex/investigate-4d-dataset-resampling-issue branch July 18, 2025 15:39
@oesteban
Copy link
Collaborator Author

@jmarabotto If you are still curious one year in, this is how this reshaping that took so much of your time works:

n_time, n_dim, n_vox = targets.shape
# Reshape to (3, n_time x n_vox)
ijk_targets = np.rollaxis(targets, 0, 2).reshape((n_dim, -1))
time_row = np.repeat(np.arange(n_time), n_vox)[None, :]
# Now targets is (4, n_vox x n_time), with indexes (t, i, j, k)
# t is the slowest-changing axis, so we put it first
targets = np.vstack((time_row, ijk_targets))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant