def run_feat(bold_file, bold_folder, brainmask_file, feat_gen):
    from nipype.interfaces.fsl import ImageStats, FEAT, Info
    # from bm_functions import gen_default_feat_config
    from numpy import shape
    from textwrap import dedent

    fslFilename = bold_folder + 'feat.fsf'

    # Get the number of voxels in the 4D file
    statComp = ImageStats()
    statComp.inputs.in_file = bold_file
    statComp.inputs.op_string = '-v'

    numVox = int(statComp.run().outputs.out_stat[0])

    # Get the number of raw volumes
    statComp.inputs.split_4d = True

    numVol = shape(statComp.run().outputs.out_stat)[0]

    # Generate the file
    standard_T1_brain = Info.standard_image('MNI152_T1_2mm_brain')
    theString = feat_gen(bold_folder, bold_file, brainmask_file, standard_T1_brain, numVox, numVol)
    with open(fslFilename,'w') as out_file:
        out_file.write(dedent(theString))
    out_file.close()   

    # Run feat using the previously manipulated config
    runFeat = FEAT(fsf_file = fslFilename)
    # Run and pass back the foldername
    return runFeat.run().outputs.feat_dir
def run_feat(bold_file, bold_folder, brainmask_file, feat_gen):
    from nipype.interfaces.fsl import ImageStats, FEAT, Info
    # from bm_functions import gen_default_feat_config
    from numpy import shape
    from textwrap import dedent

    fslFilename = bold_folder + 'feat.fsf'

    # Get the number of voxels in the 4D file
    statComp = ImageStats()
    statComp.inputs.in_file = bold_file
    statComp.inputs.op_string = '-v'

    numVox = int(statComp.run().outputs.out_stat[0])

    # Get the number of raw volumes
    statComp.inputs.split_4d = True

    numVol = shape(statComp.run().outputs.out_stat)[0]

    # Generate the file
    standard_T1_brain = Info.standard_image('MNI152_T1_2mm_brain')
    theString = feat_gen(bold_folder, bold_file, brainmask_file,
                         standard_T1_brain, numVox, numVol)
    with open(fslFilename, 'w') as out_file:
        out_file.write(dedent(theString))
    out_file.close()

    # Run feat using the previously manipulated config
    runFeat = FEAT(fsf_file=fslFilename)
    # Run and pass back the foldername
    return runFeat.run().outputs.feat_dir
Beispiel #3
0
def run_invert_T1(subj, T1_inv_path, betfMRI_folder, betMRI_folder):
    print("\n    5.Calculating inverse T1")
    stats = ImageStats(in_file=opj(betMRI_folder, subj, 'T1_brain.nii.gz'),
                       op_string='-R')
    T1minmax = stats.run()
    stats = ImageStats(in_file=opj(betfMRI_folder, subj, 'mean_brain.nii.gz'),
                       op_string='-R')
    EPIminmax = stats.run()
    factor = (T1minmax.outputs.out_stat[1] - T1minmax.outputs.out_stat[0]) / (
        EPIminmax.outputs.out_stat[1] - EPIminmax.outputs.out_stat[0])
    os.system("fslmaths " + opj(betMRI_folder, subj, 'T1_brain.nii.gz') +
              " -mul -1" + " -add " + str(T1minmax.outputs.out_stat[1]) +
              " -mul " + str(factor) + " " +
              opj(betMRI_folder, subj, 'T1_brain_inv.nii.gz'))
Beispiel #4
0
def fslstats(infile, mask):
    stats = ImageStats()
    stats.inputs.in_file = infile
    stats.inputs.op_string = '-M'
    stats.inputs.mask_file = mask
    cout = stats.run()
    return cout.outputs.out_stat
Beispiel #5
0
def fslstats(infile, mask):
    stats = ImageStats()
    stats.inputs.in_file = infile
    stats.inputs.op_string = '-M'
    stats.inputs.mask_file = mask
    cout = stats.run()
    return cout.outputs.out_stat
Beispiel #6
0
def fslmath_imagestats(input_file, operation, output_prefix):
    from nipype.interfaces.fsl import ImageStats
    import os

    statsM = ImageStats(in_file=input_file, op_string= operation)
    print "ImageStats [" + os.path.basename(input_file) + "]:" + statsM.cmdline
    res = statsM.run()
    return res.outputs.out_stat
Beispiel #7
0
def get_volume(mask, thresh, out_file):
    Mask = MathsCommand(in_file = mask,
                        args = "-thr {0} -bin".format(thresh),
                        out_file=out_file)
    Mout = Mask.run()
    Volume = ImageStats(in_file = mask, op_string = '-l {0} -V'.format(thresh))
    Vout=Volume.run()
    outstat = Vout.outputs.out_stat
    return outstat[1]
Beispiel #8
0
def get_volume(mask):
    """
    Fslstats -V returns volume [voxels mm3]
    Fslstats -M returns mean value of non-zero voxels
    Multiplying these gives the partial volume estimate
    """
    Volume = ImageStats(in_file = mask, op_string = '-V -M')
    Vout=Volume.run()
    outstat = Vout.outputs.out_stat
    return outstat[1] * outstat[2]
Beispiel #9
0
def fslstats(infile, mask):
    """
    Wrapper for fslstats. Takes input file and extract mean from specified ROI mask
    """
    stats = ImageStats()
    stats.inputs.in_file = infile
    stats.inputs.op_string = '-k %s -M'
    stats.inputs.mask_file = mask
    cout = stats.run()
    return cout.outputs.out_stat