Exemple #1
0
def test_smooth(create_files_in_directory_plus_output_type):
    files, testdir, out_ext = create_files_in_directory_plus_output_type

    # Get the command
    smoother = fsl.IsotropicSmooth(in_file="a.nii", out_file="b.nii")

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

    # Test that smoothing kernel is mandatory
    with pytest.raises(ValueError):
        smoother.run()

    # Test smoothing kernels
    cmdline = "fslmaths a.nii -s {:.5f} b.nii"
    for val in [0, 1.0, 1, 25, 0.5, 8 / 3.0]:
        smoother = fsl.IsotropicSmooth(in_file="a.nii",
                                       out_file="b.nii",
                                       sigma=val)
        assert smoother.cmdline == cmdline.format(val)
        smoother = fsl.IsotropicSmooth(in_file="a.nii",
                                       out_file="b.nii",
                                       fwhm=val)
        val = float(val) / np.sqrt(8 * np.log(2))
        assert smoother.cmdline == cmdline.format(val)

    # Test automatic naming
    smoother = fsl.IsotropicSmooth(in_file="a.nii", sigma=5)
    assert smoother.cmdline == "fslmaths a.nii -s {:.5f} {}".format(
        5, os.path.join(testdir, "a_smooth{}".format(out_ext)))
Exemple #2
0
def test_smooth(fsl_output_type=None):
    prev_type = set_output_type(fsl_output_type)
    files, testdir, origdir, out_ext = create_files_in_directory()

    # Get the command
    smoother = fsl.IsotropicSmooth(in_file="a.nii", out_file="b.nii")

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

    # Test that smoothing kernel is mandatory
    yield assert_raises, ValueError, smoother.run

    # Test smoothing kernels
    cmdline = "fslmaths a.nii -s %.5f b.nii"
    for val in [0, 1., 1, 25, 0.5, 8 / 3.]:
        smoother = fsl.IsotropicSmooth(in_file="a.nii", out_file="b.nii", sigma=val)
        yield assert_equal, smoother.cmdline, cmdline % val
        smoother = fsl.IsotropicSmooth(in_file="a.nii", out_file="b.nii", fwhm=val)
        val = float(val) / np.sqrt(8 * np.log(2))
        yield assert_equal, smoother.cmdline, cmdline % val

    # Test automatic naming
    smoother = fsl.IsotropicSmooth(in_file="a.nii", sigma=5)
    yield assert_equal, smoother.cmdline, "fslmaths a.nii -s %.5f %s" % (5, os.path.join(testdir, "a_smooth%s" % out_ext))

    # Clean up our mess
    clean_directory(testdir, origdir)
    set_output_type(prev_type)
Exemple #3
0
def smooth_img(img, fwhm):

    smth = math.IsotropicSmooth()
    smth.inputs.in_file = img
    smth.inputs.fwhm = fwhm
    smth.inputs.out_file = img
    smth.inputs.output_type = 'NIFTI_GZ'
    smth.inputs.ignore_exception = True
    smth.run()
Exemple #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()