Exemplo n.º 1
0
if args.json is not None:
    json_file = args.json
else:
    json_file = "se_script_config.json"
    
with open(json_file) as data_file:    
    config = json.load(data_file)

rh_mesh = TriMesh_Vtk(args.rh_surface, None)
lh_mesh = TriMesh_Vtk(args.lh_surface, None)

run = config["run"]
if run["translate"]:
    t = fsf.get_xras_translation(args.mask)
    rh_mesh.set_vertices(rh_mesh.vertices_translation(t))
    lh_mesh.set_vertices(lh_mesh.vertices_translation(t))
    print "xras translation", t

if run["space"]:
    if config["space"]["auto"]:
        vox = fsf.get_nifti_voxel_space(args.mask)
        world = fsf.get_nifti_voxel_space(args.mask)
    else: 
        vox = config["space"]["vox"]
        world = config["space"]["world"]
        
    rh_mesh = fsf.vox_to_world(rh_mesh, vox, world)
    lh_mesh = fsf.vox_to_world(lh_mesh, vox, world)
    
    
Exemplo n.º 2
0
T = img.affine[:3,3]
z = img.header.get_zooms()
mid_point = np.array(img.shape, dtype=np.float)/2.0

# Input assert
assert not(args.ir and args.r), "--ir or --r option"
assert not(args.it and args.t), "--it or --t option"
assert not(args.im and args.m and args.imz and args.mz ), "--m,im,mz or imz option"
assert not(args.tr and args.itr and args.tir and args.itir), "--tr,itr,tir or itir option"


mesh = TriMesh_Vtk(surface_file_in, None)
    
if args.test :
    tranfo = [-2,33,12]
    mesh.set_vertices(mesh.vertices_translation(tranfo))
    print "test : " + str(tranfo)
    
#todo nii rotation before or after translation?!?!?!
if args.r :
    tranfo = R
    mesh.set_vertices(mesh.vertices_rotation(tranfo))
    print "r : " + str(tranfo)
elif args.ir :
    tranfo = R.T
    mesh.set_vertices(mesh.vertices_rotation(R))
    print "ir : " + str(tranfo)
    
# nii translation
if args.t:
    tranfo = T
Exemplo n.º 3
0
    
    # Find freesurfer transformation
    transform_command_line = "mri_info --cras " + nii_name + " --o " +  temp_file_dir
    print "run :", transform_command_line
    os.system(transform_command_line)
    
    print "read :", temp_file_dir
    open_file = open(temp_file_dir, 'r')
    center_ras = open_file.read()
    open_file.close()
    os.remove(temp_file_dir)
    os.rmdir(temp_dir)
    
    print center_ras
    translate = np.array([float(x) for x in center_ras.split()])# temp HACK
    mesh.set_vertices(mesh.vertices_translation(translate))
    print "cras", translate
    
    
if args.fx or args.fy or args.fz:
    flip = [-1 if args.fx else 1, 
            -1 if args.fy else 1,
            -1 if args.fz else 1]
    print "flip:", flip
    f_triangles, f_vertices = mesh.flip_triangle_and_vertices(flip)
    mesh.set_vertices(f_vertices)
    mesh.set_triangles(f_triangles)
    
    
volume_nib = nib.load(nii_name)
if not args.no_lps: