示例#1
0
def test_mask(fsl_output_type=None):
    prev_type = set_output_type(fsl_output_type)
    files, testdir, origdir, out_ext = create_files_in_directory()

    # Get the command
    masker = fsl.ApplyMask(in_file="a.nii", out_file="c.nii")

    # Test the underlying command
    yield assert_equal, masker.cmd, "fslmaths"

    # Test that the mask image is mandatory
    yield assert_raises, ValueError, masker.run

    # Test setting the mask image
    masker.inputs.mask_file = "b.nii"
    yield assert_equal, masker.cmdline, "fslmaths a.nii -mas b.nii c.nii"

    # Test auto name generation
    masker = fsl.ApplyMask(in_file="a.nii", mask_file="b.nii")
    yield assert_equal, masker.cmdline, "fslmaths a.nii -mas b.nii " + os.path.join(
        testdir, "a_masked%s" % out_ext)

    # Clean up our mess
    clean_directory(testdir, origdir)
    set_output_type(prev_type)
示例#2
0
def mask_img(img, mask):

    msk = math.ApplyMask()
    msk.inputs.in_file = img
    msk.inputs.mask_file = mask
    msk.inputs.out_file = img
    msk.inputs.output_type = 'NIFTI_GZ'
    msk.inputs.ignore_exception = True
    msk.run()
示例#3
0
def test_mask(create_files_in_directory):
    files, testdir, out_ext = create_files_in_directory

    # Get the command
    masker = fsl.ApplyMask(in_file="a.nii", out_file="c.nii")

    # Test the underlying command
    assert masker.cmd == "fslmaths"

    # Test that the mask image is mandatory
    with pytest.raises(ValueError):
        masker.run()

    # Test setting the mask image
    masker.inputs.mask_file = "b.nii"
    assert masker.cmdline == "fslmaths a.nii -mas b.nii c.nii"

    # Test auto name generation
    masker = fsl.ApplyMask(in_file="a.nii", mask_file="b.nii")
    assert masker.cmdline == "fslmaths a.nii -mas b.nii " + os.path.join(testdir, "a_masked%s" % out_ext)
示例#4
0
# define working dir for smoothing
work_dir_smooth = os.path.join(os.getcwd(), 'smooth')
if not os.path.exists(work_dir_smooth):
    os.makedirs(work_dir_smooth)
os.chdir(work_dir_smooth)

# Step#1 get a brain mask for func2mni image
from nipype.interfaces import afni as afni
automask = afni.Automask()
automask.inputs.in_file = rest_mni
automask.inputs.outputtype = "NIFTI_GZ"
automask.run()

# Step#2 smooth func2mni image
from nipype.interfaces.fsl import maths
smooth = maths.IsotropicSmooth()
smooth.inputs.in_file = rest_mni
smooth.inputs.fwhm = 6
smooth.run()

## Step#3 mask the smoothed image
from nipype.interfaces.fsl import maths
maskApp = maths.ApplyMask()
maskApp.inputs.in_file = 'rest_preprocessed2mni_smooth.nii.gz'
maskApp.inputs.mask_file = 'rest_preprocessed2mni_mask.nii.gz'
maskApp.inputs.out_file = os.path.join(work_dir,
                                       'rest_preprocessed2mni_sm.nii.gz')
maskApp.inputs.output_type = 'NIFTI_GZ'
maskApp.run()
    # START PIPELINE
    # inputmask = Node(IdentityInterface(fields=['mask_file']), name='inputmask')

    if args.prep_pipeline.startswith("fsl"):
        masker = Node(ApplyWarp(
            in_file = cf_files['bold'],
            field_file=cf_files['warpfile'],
            ref_file=cf_files['standard'],
            out_file = cf_files['masked'],
            mask_file = cf_files['standard_mask']
        ), name = 'masker')
        #inputmask.inputs.mask_file = cf_files['standard_mask']
    else:
        masker = Node(maths.ApplyMask(
            in_file=cf_files['bold'],
            out_file=cf_files['masked'],
            mask_file=cf_files['standard_mask']
            ), name='masker')


    bim = Node(afni.BlurInMask(
        out_file=cf_files['smoothed'],
        mask = cf_files['standard_mask'],
        fwhm=5.0
    ), name='bim')

    l1 = Node(SpecifyModel(
        event_files=EVfiles,
        realignment_parameters=confoundsfile,
        input_units='secs',
        time_repetition=2,