Skip to content

Commit b11551e

Browse files
authored
FIX: Pad BSpline design matrix (#319)
1 parent 7057072 commit b11551e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sdcflows/transform.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,15 @@ def grid_bspline_weights(target_nii, ctrl_nii, dtype="float32"):
406406

407407
# Calculate the index component of samples w.r.t. B-Spline knots along current axis
408408
x = nb.affines.apply_affine(target_to_grid, coords.T)[:, axis]
409+
pad_left = max(int(-np.rint(x.min())), 0)
410+
pad_right = max(int(np.rint(x.max()) - knots_shape[axis]), 0)
409411

410412
# BSpline.design_matrix requires all x be within -4 and 4 padding
411413
# This padding results from the B-Spline degree (3) plus one
412-
t = np.arange(-4, knots_shape[axis] + 4, dtype=dtype)
414+
t = np.arange(-4 - pad_left, knots_shape[axis] + 4 + pad_right, dtype=dtype)
413415

414416
# Calculate K x N collocation matrix (discarding extra padding)
415-
colloc_ax = BSpline.design_matrix(x, t, 3)[:, 2:-2]
417+
colloc_ax = BSpline.design_matrix(x, t, 3)[:, (2 + pad_left):-(2 + pad_right)]
416418
# Design matrix returns K x N and we want N x K
417419
wd.append(colloc_ax.T.tocsr())
418420

0 commit comments

Comments
 (0)