Skip to content

Commit fcdbb54

Browse files
committed
ENH: Allow Jacobian determinant modulation to be selected
1 parent 7f4b302 commit fcdbb54

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

fmriprep/interfaces/resampling.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ResampleSeriesInputSpec(TraitedSpec):
4949
"k-",
5050
desc="the phase-encoding direction corresponding to in_data",
5151
)
52+
jacobian = traits.Bool(mandatory=True, desc="Whether to apply Jacobian correction")
5253
num_threads = traits.Int(1, usedefault=True, desc="Number of threads to use for resampling")
5354
output_data_type = traits.Str("float32", usedefault=True, desc="Data type of output image")
5455
order = traits.Int(3, usedefault=True, desc="Order of interpolation (0=nearest, 3=cubic)")
@@ -105,6 +106,7 @@ def _run_interface(self, runtime):
105106
transforms=transforms,
106107
fieldmap=fieldmap,
107108
pe_info=pe_info,
109+
jacobian=self.inputs.jacobian,
108110
nthreads=self.inputs.num_threads,
109111
output_dtype=self.inputs.output_data_type,
110112
order=self.inputs.order,
@@ -217,6 +219,7 @@ def resample_vol(
217219
data: np.ndarray,
218220
coordinates: np.ndarray,
219221
pe_info: tuple[int, float],
222+
jacobian: bool,
220223
hmc_xfm: np.ndarray | None,
221224
fmap_hz: np.ndarray,
222225
output: np.dtype | np.ndarray | None = None,
@@ -282,8 +285,6 @@ def resample_vol(
282285
vsm = fmap_hz * pe_info[1]
283286
coordinates[pe_info[0], ...] += vsm
284287

285-
jacobian = 1 + np.gradient(vsm, axis=pe_info[0])
286-
287288
result = ndi.map_coordinates(
288289
data,
289290
coordinates,
@@ -293,14 +294,18 @@ def resample_vol(
293294
cval=cval,
294295
prefilter=prefilter,
295296
)
296-
result *= jacobian
297+
298+
if jacobian:
299+
result *= 1 + np.gradient(vsm, axis=pe_info[0])
300+
297301
return result
298302

299303

300304
async def resample_series_async(
301305
data: np.ndarray,
302306
coordinates: np.ndarray,
303307
pe_info: list[tuple[int, float]],
308+
jacobian: bool,
304309
hmc_xfms: list[np.ndarray] | None,
305310
fmap_hz: np.ndarray,
306311
output_dtype: np.dtype | None = None,
@@ -361,6 +366,7 @@ async def resample_series_async(
361366
data,
362367
coordinates,
363368
pe_info[0],
369+
jacobian,
364370
hmc_xfms[0] if hmc_xfms else None,
365371
fmap_hz,
366372
output_dtype,
@@ -384,6 +390,7 @@ async def resample_series_async(
384390
data=volume,
385391
coordinates=coordinates,
386392
pe_info=pe_info[volid],
393+
jacobian=jacobian,
387394
hmc_xfm=hmc_xfms[volid] if hmc_xfms else None,
388395
fmap_hz=fmap_hz,
389396
output=out_array[..., volid],
@@ -407,6 +414,7 @@ def resample_series(
407414
data: np.ndarray,
408415
coordinates: np.ndarray,
409416
pe_info: list[tuple[int, float]],
417+
jacobian: bool,
410418
hmc_xfms: list[np.ndarray] | None,
411419
fmap_hz: np.ndarray,
412420
output_dtype: np.dtype | None = None,
@@ -467,6 +475,7 @@ def resample_series(
467475
data=data,
468476
coordinates=coordinates,
469477
pe_info=pe_info,
478+
jacobian=jacobian,
470479
hmc_xfms=hmc_xfms,
471480
fmap_hz=fmap_hz,
472481
output_dtype=output_dtype,
@@ -485,6 +494,7 @@ def resample_image(
485494
transforms: nt.TransformChain,
486495
fieldmap: nb.Nifti1Image | None,
487496
pe_info: list[tuple[int, float]] | None,
497+
jacobian: bool = True,
488498
nthreads: int = 1,
489499
output_dtype: np.dtype | str | None = 'f4',
490500
order: int = 3,
@@ -566,6 +576,7 @@ def resample_image(
566576
data=source.get_fdata(dtype='f4'),
567577
coordinates=mapped_coordinates.T.reshape((3, *target.shape[:3])),
568578
pe_info=pe_info,
579+
jacobian=jacobian,
569580
hmc_xfms=hmc_xfms,
570581
fmap_hz=fieldmap.get_fdata(dtype='f4'),
571582
output_dtype=output_dtype,

0 commit comments

Comments
 (0)