예제 #1
0
파일: warping.py 프로젝트: baothien/tiensy
def warp_fa(input_filename, output_filename=None, output_fmatrix=None, input_ref = '/usr/share/fsl/data/standard/FMRIB58_FA_1mm.nii.gz'):
   
    print "Doing nonlinear (flirt/fnirt) registration of FA volume..."
    
    if output_filename == None:
        filename_save = input_filename.split('.')[0]+'_flirt_out.nii.gz'
    else:
        filename_save = os.path.abspath(output_filename)

    if output_fmatrix == None:
        filename_save_matrix = input_filename.split('.')[0]+'_flirt.mat'
    else:
        filename_save_matrix = os.path.abspath(output_fmatrix)    
    
    nonlin_nii = 'nonlinear.nii.gz'
    invw_nii = 'invw.nii.gz'
    disp_nii = 'disp.nii.gz'
    dispa_nii = 'dispa.nii.gz'

    print "Creating displacements...",
    create_displacements(input_filename, filename_save_matrix, nonlin_nii, invw_nii, disp_nii, dispa_nii,input_ref)
    print "Done."

    print "Warping FA...",
    warp_displacements(input_filename,
                       flaff = filename_save_matrix,
                       fdis = disp_nii,
                       fref = input_ref,
                       ffaw = filename_save)
                       
    print 'Saving to ', filename_save, ' and ', filename_save_matrix 
    
    return filename_save, filename_save_matrix
예제 #2
0
        nib.save(data_img, data_filename)
        
#        dpy_filename = basedir_reconstruction + 'tracks.dpy'
#        print "Saving tractography:", dpy_filename
#        dpw = Dpy(dpy_filename, 'w')
#        dpw.write_tracks(tensor_tracks)
#        dpw.close()
        
        fa_filename = basedir_reconstruction + 'fa_resample.nii.gz'
        print "Doing nonlinear (flirt/fnirt) registration of FA volume."
        flirt_affine = basedir_reconstruction + 'flirt.mat'
        flirt_displacements = basedir_reconstruction + 'displacements.nii.gz'
        print "Reference:", fsl_ref
        flirt_warp = basedir_reconstruction + 'fa_resample_warped.nii.gz'
        nonlin_nii = basedir_reconstruction + 'nonlinear.nii.gz'
        invw_nii = basedir_reconstruction + 'invw.nii.gz'
        disp_nii = basedir_reconstruction + 'disp.nii.gz'
        dispa_nii = basedir_reconstruction + 'dispa.nii.gz'

        print "Creating displacements...",
        create_displacements(fa_filename, flirt_affine, nonlin_nii, invw_nii, disp_nii, dispa_nii,fsl_ref)
        print "Done."

        print "Warping FA...",
        warp_displacements(fa_filename,
                           flaff = flirt_affine,
                           fdis = disp_nii,
                           fref = fsl_ref,
                           ffaw = flirt_warp)
        print "Done."