示例#1
0
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  # noqa
        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 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
def headmsk_wf(name='HeadMaskWorkflow'):
    """Computes a head mask as in [Mortamet2009]_."""

    has_dipy = False
    try:
        from dipy.denoise import nlmeans
        from nipype.interfaces.dipy import Denoise
        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 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')
                                             ])])
        return workflow

    getwm = pe.Node(niu.Function(input_names=['in_file'],
                                 output_names=['out_file'],
                                 function=_get_wm),
                    name='GetWM')
    denoise = pe.Node(Denoise(), name='Denoise')
    gradient = pe.Node(niu.Function(input_names=['in_file'],
                                    output_names=['out_file'],
                                    function=image_gradient),
                       name='Grad')
    thresh = pe.Node(niu.Function(input_names=['in_file'],
                                  output_names=['out_file'],
                                  function=gradient_threshold),
                     name='GradientThreshold')

    workflow.connect([(inputnode, getwm, [('in_segm', 'in_file')]),
                      (inputnode, denoise, [('in_file', 'in_file')]),
                      (getwm, denoise, [('out_file', 'noise_mask')]),
                      (denoise, gradient, [('out_file', 'in_file')]),
                      (gradient, thresh, [('out_file', 'in_file')]),
                      (thresh, outputnode, [('out_file', 'out_file')])])

    return workflow
示例#3
0
def headmsk_wf(name="HeadMaskWorkflow"):
    """
    Computes a head mask as in [Mortamet2009]_.

    .. workflow::

        from mriqc.testing import mock_config
        from mriqc.workflows.anatomical import headmsk_wf
        with mock_config():
            wf = headmsk_wf()

    """

    use_bet = config.workflow.headmask.upper() == "BET"
    has_dipy = False

    if not use_bet:
        try:
            from dipy.denoise import nlmeans  # noqa

            has_dipy = True
        except ImportError:
            pass

    if not use_bet and not has_dipy:
        raise RuntimeError(
            "DIPY is not installed and ``config.workflow.headmask`` is not BET."
        )

    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:
        # Alternative for when dipy is not installed
        bet = pe.Node(fsl.BET(surfaces=True), name="fsl_bet")

        # fmt: off
        workflow.connect([
            (inputnode, bet, [("in_file", "in_file")]),
            (bet, outputnode, [('outskin_mask_file', "out_file")]),
        ])
        # fmt: on

    else:
        from 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", "sigma"],
                output_names=["out_file"],
                function=image_gradient,
            ),
            name="Grad",
        )
        thresh = pe.Node(
            niu.Function(
                input_names=["in_file", "in_segm", "aniso", "thresh"],
                output_names=["out_file"],
                function=gradient_threshold,
            ),
            name="GradientThreshold",
        )
        if config.workflow.species != "human":
            calc_sigma = pe.Node(
                niu.Function(
                    input_names=["in_file"],
                    output_names=["sigma"],
                    function=sigma_calc,
                ),
                name="calc_sigma",
            )
            workflow.connect([
                (inputnode, calc_sigma, [("in_file", "in_file")]),
                (calc_sigma, gradient, [("sigma", "sigma")]),
            ])

            thresh.inputs.aniso = True
            thresh.inputs.thresh = 4.0

        # fmt: off
        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")]),
        ])
        # fmt: on

    return workflow