Skip to content

Commit

Permalink
Merge pull request #391 from nipreps/enh/jacobian
Browse files Browse the repository at this point in the history
ENH: Implement Jacobian weighting during unwarp
  • Loading branch information
effigies authored Oct 2, 2023
2 parents 50ace2a + c8a4f3d commit 3e318c5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sdcflows/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ def _sdc_unwarp(
# Map voxel coordinates applying the VSM
# The VSM is just the displacements field given in index coordinates
# voxcoords is the deformation field, i.e., the target position of each voxel
coordinates[pe_info[0], ...] += fmap_hz * pe_info[1]
vsm = fmap_hz * pe_info[1]
coordinates[pe_info[0], ...] += vsm

# The Jacobian determinant image is the amount of stretching in the PE direction.
# Using central differences accounts for the shift in neighboring voxels.
# The full Jacobian at each voxel would be a 3x3 matrix, but because there is
# only warping in one direction, we end up with a diagonal matrix with two 1s.
# The following is the other entry at each voxel, and hence the determinant.
jacobian = 1 + np.gradient(vsm, axis=pe_info[0])

resampled = ndi.map_coordinates(
data,
Expand All @@ -102,7 +110,7 @@ def _sdc_unwarp(
mode=mode,
cval=cval,
prefilter=prefilter,
)
) * jacobian

return resampled

Expand Down

0 comments on commit 3e318c5

Please sign in to comment.