Skip to content

Commit 924cd45

Browse files
committed
tunning hmc registration
1 parent 9c98d0c commit 924cd45

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

nipype/workflows/dmri/preprocess/epi.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,19 @@ def hmc_pipeline(name='motion_correct'):
299299
outputnode.out_xfms - list of transformation matrices
300300
301301
"""
302-
params = dict(dof=6, interp='spline', padding_size=10, save_log=True,
302+
params = dict(dof=6, padding_size=10, save_log=True,
303303
searchr_x=[-3, 3], searchr_y=[-3, 3], searchr_z=[-3, 3],
304-
fine_search=1, coarse_search=2)
305-
# cost='normmi', cost_func='normmi', bins=64,
304+
fine_search=1, coarse_search=2,
305+
cost='mutualinfo', cost_func='mutualinfo', bins=64)
306306

307307
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'ref_num',
308308
'in_bvec', 'in_bval', 'in_mask']), name='inputnode')
309309
refid = pe.Node(niu.IdentityInterface(fields=['ref_num']),
310310
name='RefVolume')
311311
pick_ref = pe.Node(fsl.ExtractROI(t_size=1), name='GetRef')
312-
pick_mov = pe.Node(niu.Function(input_names=['in_file', 'volid'],
313-
output_names=['out_file'], function=remove_comp),
314-
name='GetMovingDWs')
312+
pick_mov = pe.Node(niu.Function(input_names=['in_file', 'in_bval', 'volid'],
313+
output_names=['out_file', 'out_bval'],
314+
function=remove_comp), name='GetMovingDWs')
315315
flirt = dwi_flirt(flirt_param=params)
316316
insmat = pe.Node(niu.Function(input_names=['inlist', 'volid'],
317317
output_names=['out'], function=insert_mat),
@@ -327,12 +327,14 @@ def hmc_pipeline(name='motion_correct'):
327327
wf.connect([
328328
(inputnode, refid, [(('ref_num', _checkrnum), 'ref_num')])
329329
,(inputnode, pick_ref, [('in_file', 'in_file')])
330+
,(inputnode, pick_mov, [('in_file', 'in_file'),
331+
('in_bval', 'in_bval')])
332+
,(inputnode, flirt, [('in_mask', 'inputnode.ref_mask')])
330333
,(refid, pick_ref, [('ref_num', 't_min')])
331-
,(inputnode, pick_mov, [('in_file', 'in_file')])
332334
,(refid, pick_mov, [('ref_num', 'volid')])
333-
,(inputnode, flirt, [('in_file', 'inputnode.in_file'),
334-
('in_mask', 'inputnode.ref_mask'),
335-
('in_bval', 'inputnode.in_bval')])
335+
,(pick_mov, flirt, [('out_file', 'inputnode.in_file'),
336+
('out_bval', 'inputnode.in_bval')])
337+
336338
,(pick_ref, flirt, [('roi_file', 'inputnode.reference')])
337339
,(flirt, insmat, [('outputnode.out_xfms', 'inlist')])
338340
,(refid, insmat, [('ref_num', 'volid')])

nipype/workflows/dmri/preprocess/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# vi: set ft=python sts=4 ts=4 sw=4 et:
55
# @Author: oesteban
66
# @Date: 2014-08-30 10:53:13
7-
# @Last Modified by: oesteban
8-
# @Last Modified time: 2014-09-04 16:44:28
7+
# @Last Modified by: Oscar Esteban
8+
# @Last Modified time: 2014-09-04 17:21:33
99
import nipype.pipeline.engine as pe
1010
import nipype.interfaces.utility as niu
1111
from nipype.interfaces import fsl
@@ -231,7 +231,7 @@ def extract_bval(in_dwi, in_bval, b=0, out_file=None):
231231
return out_file
232232

233233

234-
def remove_comp(in_file, volid=0, out_file=None):
234+
def remove_comp(in_file, in_bval, volid=0, out_file=None):
235235
"""
236236
Removes the volume ``volid`` from the 4D nifti file
237237
"""
@@ -249,17 +249,24 @@ def remove_comp(in_file, volid=0, out_file=None):
249249
im = nb.load(in_file)
250250
data = im.get_data()
251251
hdr = im.get_header().copy()
252+
bval = np.loadtxt(in_bval)
252253

253254
if volid == 0:
254255
data = data[..., 1:]
256+
bval = bval[1:]
255257
elif volid == (data.shape[-1] - 1):
256258
data = data[..., :-1]
259+
bval = bval[:-1]
257260
else:
258261
data = np.concatenate((data[..., :volid], data[..., (volid + 1):]),
259262
axis=3)
263+
bval = np.hstack((bval[:volid], bval[(volid + 1):]))
260264
hdr.set_data_shape(data.shape)
261265
nb.Nifti1Image(data, im.get_affine(), hdr).to_filename(out_file)
262-
return out_file
266+
267+
out_bval = op.abspath('bval_extract.txt')
268+
np.savetxt(out_bval, bval)
269+
return out_file, out_bval
263270

264271

265272
def insert_mat(inlist, volid=0):

0 commit comments

Comments
 (0)