@@ -49,6 +49,7 @@ class ResampleSeriesInputSpec(TraitedSpec):
49
49
"k-" ,
50
50
desc = "the phase-encoding direction corresponding to in_data" ,
51
51
)
52
+ jacobian = traits .Bool (mandatory = True , desc = "Whether to apply Jacobian correction" )
52
53
num_threads = traits .Int (1 , usedefault = True , desc = "Number of threads to use for resampling" )
53
54
output_data_type = traits .Str ("float32" , usedefault = True , desc = "Data type of output image" )
54
55
order = traits .Int (3 , usedefault = True , desc = "Order of interpolation (0=nearest, 3=cubic)" )
@@ -105,6 +106,7 @@ def _run_interface(self, runtime):
105
106
transforms = transforms ,
106
107
fieldmap = fieldmap ,
107
108
pe_info = pe_info ,
109
+ jacobian = self .inputs .jacobian ,
108
110
nthreads = self .inputs .num_threads ,
109
111
output_dtype = self .inputs .output_data_type ,
110
112
order = self .inputs .order ,
@@ -217,6 +219,7 @@ def resample_vol(
217
219
data : np .ndarray ,
218
220
coordinates : np .ndarray ,
219
221
pe_info : tuple [int , float ],
222
+ jacobian : bool ,
220
223
hmc_xfm : np .ndarray | None ,
221
224
fmap_hz : np .ndarray ,
222
225
output : np .dtype | np .ndarray | None = None ,
@@ -282,8 +285,6 @@ def resample_vol(
282
285
vsm = fmap_hz * pe_info [1 ]
283
286
coordinates [pe_info [0 ], ...] += vsm
284
287
285
- jacobian = 1 + np .gradient (vsm , axis = pe_info [0 ])
286
-
287
288
result = ndi .map_coordinates (
288
289
data ,
289
290
coordinates ,
@@ -293,14 +294,18 @@ def resample_vol(
293
294
cval = cval ,
294
295
prefilter = prefilter ,
295
296
)
296
- result *= jacobian
297
+
298
+ if jacobian :
299
+ result *= 1 + np .gradient (vsm , axis = pe_info [0 ])
300
+
297
301
return result
298
302
299
303
300
304
async def resample_series_async (
301
305
data : np .ndarray ,
302
306
coordinates : np .ndarray ,
303
307
pe_info : list [tuple [int , float ]],
308
+ jacobian : bool ,
304
309
hmc_xfms : list [np .ndarray ] | None ,
305
310
fmap_hz : np .ndarray ,
306
311
output_dtype : np .dtype | None = None ,
@@ -361,6 +366,7 @@ async def resample_series_async(
361
366
data ,
362
367
coordinates ,
363
368
pe_info [0 ],
369
+ jacobian ,
364
370
hmc_xfms [0 ] if hmc_xfms else None ,
365
371
fmap_hz ,
366
372
output_dtype ,
@@ -384,6 +390,7 @@ async def resample_series_async(
384
390
data = volume ,
385
391
coordinates = coordinates ,
386
392
pe_info = pe_info [volid ],
393
+ jacobian = jacobian ,
387
394
hmc_xfm = hmc_xfms [volid ] if hmc_xfms else None ,
388
395
fmap_hz = fmap_hz ,
389
396
output = out_array [..., volid ],
@@ -407,6 +414,7 @@ def resample_series(
407
414
data : np .ndarray ,
408
415
coordinates : np .ndarray ,
409
416
pe_info : list [tuple [int , float ]],
417
+ jacobian : bool ,
410
418
hmc_xfms : list [np .ndarray ] | None ,
411
419
fmap_hz : np .ndarray ,
412
420
output_dtype : np .dtype | None = None ,
@@ -467,6 +475,7 @@ def resample_series(
467
475
data = data ,
468
476
coordinates = coordinates ,
469
477
pe_info = pe_info ,
478
+ jacobian = jacobian ,
470
479
hmc_xfms = hmc_xfms ,
471
480
fmap_hz = fmap_hz ,
472
481
output_dtype = output_dtype ,
@@ -485,6 +494,7 @@ def resample_image(
485
494
transforms : nt .TransformChain ,
486
495
fieldmap : nb .Nifti1Image | None ,
487
496
pe_info : list [tuple [int , float ]] | None ,
497
+ jacobian : bool = True ,
488
498
nthreads : int = 1 ,
489
499
output_dtype : np .dtype | str | None = 'f4' ,
490
500
order : int = 3 ,
@@ -566,6 +576,7 @@ def resample_image(
566
576
data = source .get_fdata (dtype = 'f4' ),
567
577
coordinates = mapped_coordinates .T .reshape ((3 , * target .shape [:3 ])),
568
578
pe_info = pe_info ,
579
+ jacobian = jacobian ,
569
580
hmc_xfms = hmc_xfms ,
570
581
fmap_hz = fieldmap .get_fdata (dtype = 'f4' ),
571
582
output_dtype = output_dtype ,
0 commit comments