Example #1
0
def applywarp(lst_b0, lst_fn):
    lst_fnout = []
    for i in range(len(lst_b0)):
        mat = '%s_to_mean.mat0GenericAffine.mat' % lst_b0[i]
        f_in = lst_fn[i]
        f_out = filename_wo_ext(os.path.basename(lst_fn[i])) + '_rigid.nii.gz'
        cmd = 'antsApplyTransforms -d 3 -e 3 -i %s -r %s.nii.gz -o %s -n BSpline[3] -t %s' \
                % (f_in, lst_b0[i], f_out, mat)
        run_command(cmd)
        lst_fnout.append(f_out)
    return lst_fnout
Example #2
0
def xalign(lst_b0, t):
    for i in range(len(lst_b0)):
        mat = '%s_to_mean.mat' % lst_b0[i]

        cmd = 'antsRegistration -d 3 \
                -n BSpline[3] \
                --convergence 10 \
                --transform Rigid[3] \
                --smoothing-sigmas 0mm \
                --metric MI[%s.nii.gz,%s_xenc.nii.gz,1,16] \
                -o [%s,%s_xenc.nii.gz] \
                --masks [%s,%s] \
                --shrink-factors 1 \
                ' % (bn_mean, lst_b0[i], fn_tempmat, lst_b0[i], fn_mask,
                     fn_mask)
        run_command(cmd)

        if t == 0:
            run_command('cp %s0GenericAffine.mat %s0GenericAffine.mat' %
                        (fn_tempmat, mat))
        else:
            cmd = 'ComposeMultiTransform 3 %s0GenericAffine.mat %s0GenericAffine.mat %s0GenericAffine.mat' \
                    % (mat, fn_tempmat, mat)
            #% (mat, mat, fn_tempmat)
            run_command(cmd)
Example #3
0
def init(lst_b0):
    for i in range(len(lst_b0)):
        mat = '%s_to_mean.mat' % lst_b0[i]
        #run_command('cp %s %s' % (identmat, mat))
        run_command('cp %s.nii.gz %s_xenc.nii.gz' % (lst_b0[i], lst_b0[i]))
Example #4
0
def calc(lst_b0):
    run_command('fslmerge -t %s_concat %s' %
                (bn_mean, ' '.join(['%s_xenc' % tmp for tmp in (lst_b0)])))
    run_command('fslmaths %s_concat -Tmean %s' % (bn_mean, bn_mean))
Example #5
0
                    filename).split('/')[-1].split('_')[0], middle,
                                             os.path.basename(filename))
            else:
                lst_dwi[i] = '%sordered%s_%s_%s' % (prefix, i + 1, middle,
                                                    os.path.basename(filename))

lst_b0 = []
lst_fn = []
lst_nframe = []
for i in range(len(lst_dwi)):
    fn_dwi = os.path.join(dn_base, lst_dwi[i])
    lst_fn.append(fn_dwi)
    lst_nframe.append(nib.load(fn_dwi).shape[-1])
    fn_dwi_wo_ext = filename_wo_ext(fn_dwi)
    bn_dwi = os.path.basename(fn_dwi_wo_ext)
    run_command('extract_b0_dwi_mean.py %s %s.bval %s' %
                (fn_dwi, fn_dwi_wo_ext, os.path.basename(fn_dwi)))
    lst_b0.append('%s_b0' % bn_dwi)

if False:
    subject = lst_b0[0].split('_')
    is_number = False
    for i in range(len(subject)):
        try:
            int(subject[i])
        except:
            pass
        else:
            is_number = True
        if is_number:
            break
    subject = '_'.join(subject[:i])