@@ -200,7 +200,7 @@ def init_brain_extraction_wf(name='brain_extraction_wf',
200
200
name = 'truncate_images' , iterfield = ['op1' ])
201
201
inu_n4 = pe .MapNode (
202
202
N4BiasFieldCorrection (
203
- dimension = 3 , save_bias = True , copy_header = True ,
203
+ dimension = 3 , save_bias = False , copy_header = True ,
204
204
n_iterations = [50 ] * 4 , convergence_threshold = 1e-7 , shrink_factor = 4 ,
205
205
bspline_fitting_distance = bspline_fitting_distance ),
206
206
n_procs = omp_nthreads , name = 'inu_n4' , iterfield = ['input_image' ])
@@ -265,11 +265,20 @@ def init_brain_extraction_wf(name='brain_extraction_wf',
265
265
get_brainmask = pe .Node (ImageMath (operation = 'GetLargestComponent' ),
266
266
name = 'get_brainmask' )
267
267
268
+ # Refine INU correction
269
+ inu_n4_final = pe .MapNode (
270
+ N4BiasFieldCorrection (
271
+ dimension = 3 , save_bias = True , copy_header = True ,
272
+ n_iterations = [50 ] * 5 , convergence_threshold = 1e-7 , shrink_factor = 4 ,
273
+ bspline_fitting_distance = bspline_fitting_distance ),
274
+ n_procs = omp_nthreads , name = 'inu_n4_final' , iterfield = ['input_image' ])
275
+
268
276
# Apply mask
269
277
apply_mask = pe .MapNode (ApplyMask (), iterfield = ['in_file' ], name = 'apply_mask' )
270
278
271
279
wf .connect ([
272
280
(inputnode , trunc , [('in_files' , 'op1' )]),
281
+ (inputnode , inu_n4_final , [('in_files' , 'input_image' )]),
273
282
(inputnode , init_aff , [('in_mask' , 'fixed_image_mask' )]),
274
283
(inputnode , norm , [('in_mask' , fixed_mask_trait )]),
275
284
(inputnode , map_brainmask , [(('in_files' , _pop ), 'reference_image' )]),
@@ -285,12 +294,12 @@ def init_brain_extraction_wf(name='brain_extraction_wf',
285
294
(map_brainmask , thr_brainmask , [('output_image' , 'input_image' )]),
286
295
(thr_brainmask , dil_brainmask , [('output_image' , 'op1' )]),
287
296
(dil_brainmask , get_brainmask , [('output_image' , 'op1' )]),
288
- (inu_n4 , apply_mask , [('output_image' , 'in_file' )]),
297
+ (inu_n4_final , apply_mask , [('output_image' , 'in_file' )]),
289
298
(get_brainmask , apply_mask , [('output_image' , 'mask_file' )]),
290
299
(get_brainmask , outputnode , [('output_image' , 'out_mask' )]),
291
300
(apply_mask , outputnode , [('out_file' , 'out_file' )]),
292
- (inu_n4 , outputnode , [('output_image' , 'bias_corrected' ),
293
- ('bias_image' , 'bias_image' )]),
301
+ (inu_n4_final , outputnode , [('output_image' , 'bias_corrected' ),
302
+ ('bias_image' , 'bias_image' )]),
294
303
])
295
304
296
305
if use_laplacian :
@@ -319,12 +328,15 @@ def init_brain_extraction_wf(name='brain_extraction_wf',
319
328
])
320
329
321
330
if atropos_refine :
331
+ atropos_model = atropos_model or list (ATROPOS_MODELS [bids_suffix ].values ())
322
332
atropos_wf = init_atropos_wf (
323
333
use_random_seed = atropos_use_random_seed ,
324
334
omp_nthreads = omp_nthreads ,
325
335
mem_gb = mem_gb ,
326
- in_segmentation_model = atropos_model or list ( ATROPOS_MODELS [ bids_suffix ]. values ())
336
+ in_segmentation_model = atropos_model ,
327
337
)
338
+ sel_wm = pe .Node (niu .Select (index = atropos_model [- 1 ] - 1 ), name = 'sel_wm' ,
339
+ run_without_submitting = True )
328
340
329
341
wf .disconnect ([
330
342
(get_brainmask , outputnode , [('output_image' , 'out_mask' )]),
@@ -337,6 +349,8 @@ def init_brain_extraction_wf(name='brain_extraction_wf',
337
349
('output_image' , 'inputnode.in_mask' )]),
338
350
(get_brainmask , atropos_wf , [
339
351
('output_image' , 'inputnode.in_mask_dilated' )]),
352
+ (atropos_wf , sel_wm , [('outputnode.out_tpms' , 'inlist' )]),
353
+ (sel_wm , inu_n4_final , [('out' , 'weight_image' )]),
340
354
(atropos_wf , outputnode , [
341
355
('outputnode.out_mask' , 'out_mask' )]),
342
356
(atropos_wf , apply_mask , [
0 commit comments