Skip to content

Commit d518851

Browse files
committed
FIX: Mask fieldmap before fitting spline field
Previously, we fit a spline field to the within-mask portion of a fieldmap, which could lead to large peaks outside the mask. Applying the mask to the reconstructed field can produce discontinuities in resampling. Instead of attempting to attenuate the peaks outside the mask in a smooth way, we set the fit values outside the mask to zero, and let the spline fit find a smooth field. In practice, we've found that even fields with large peaks on the edge of the mask are well fit by this method.
1 parent 71a9ae3 commit d518851

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sdcflows/interfaces/bspline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def _run_interface(self, runtime):
195195
center = np.mean(data[mask])
196196

197197
data -= center
198+
data[~mask] = 0
198199

199200
# Calculate collocation matrix from (possibly resized) image and knot grids
200201
colmat = sparse_hstack(
@@ -214,7 +215,7 @@ def _run_interface(self, runtime):
214215
alpha=self.inputs.ridge_alpha, fit_intercept=False, solver="lsqr"
215216
)
216217
for attempt in range(3):
217-
model.fit(colmat[mask.reshape(-1), :], data[mask])
218+
model.fit(colmat, data.reshape(-1))
218219
extreme = np.abs(model.coef_).max()
219220
LOGGER.debug(f"Model fit attempt {attempt}: max(|coeffs|) = {extreme}")
220221
# Normal values seem to be ~1e2, bad ~1e8. May want to tweak this if

0 commit comments

Comments
 (0)