# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import gaussian_gradient_magnitude [as 別名]
def headmsk_wf(name='HeadMaskWorkflow', use_bet=True):
"""
Computes a head mask as in [Mortamet2009]_.
.. workflow::
from mriqc.workflows.anatomical import headmsk_wf
wf = headmsk_wf()
"""
has_dipy = False
try:
from dipy.denoise import nlmeans
has_dipy = True
except ImportError:
pass
workflow = pe.Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_segm']),
name='inputnode')
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file']), name='outputnode')
if use_bet or not has_dipy:
# Alternative for when dipy is not installed
bet = pe.Node(fsl.BET(surfaces=True), name='fsl_bet')
workflow.connect([
(inputnode, bet, [('in_file', 'in_file')]),
(bet, outputnode, [('outskin_mask_file', 'out_file')])
])
else:
from niworkflows.nipype.interfaces.dipy import Denoise
enhance = pe.Node(niu.Function(
input_names=['in_file'], output_names=['out_file'], function=_enhance), name='Enhance')
estsnr = pe.Node(niu.Function(
input_names=['in_file', 'seg_file'], output_names=['out_snr'],
function=_estimate_snr), name='EstimateSNR')
denoise = pe.Node(Denoise(), name='Denoise')
gradient = pe.Node(niu.Function(
input_names=['in_file', 'snr'], output_names=['out_file'], function=image_gradient), name='Grad')
thresh = pe.Node(niu.Function(
input_names=['in_file', 'in_segm'], output_names=['out_file'], function=gradient_threshold),
name='GradientThreshold')
workflow.connect([
(inputnode, estsnr, [('in_file', 'in_file'),
('in_segm', 'seg_file')]),
(estsnr, denoise, [('out_snr', 'snr')]),
(inputnode, enhance, [('in_file', 'in_file')]),
(enhance, denoise, [('out_file', 'in_file')]),
(estsnr, gradient, [('out_snr', 'snr')]),
(denoise, gradient, [('out_file', 'in_file')]),
(inputnode, thresh, [('in_segm', 'in_segm')]),
(gradient, thresh, [('out_file', 'in_file')]),
(thresh, outputnode, [('out_file', 'out_file')])
])
return workflow