Beispiel #1
0
def align_funcs(funcs, logger):
	allmove = []
	allmoved = [funcs[0]]
	func_target = funcs[0]
	for movin in funcs[1:]:
	    tmpaff = reg.affine_register_cc(func_target, movin)
	    if tmpaff is None:
	        continue
	    displacement, translate, angles = xfm.params_from_ants(tmpaff)
	    allmove.append([translate.tolist() + angles + [displacement]])
	    moved = reg.apply_transform(movin, tmpaff, target = func_target)
	    allmoved.append(moved)
	return allmove, allmoved
Beispiel #2
0
 reg.function_logger(rootdir)
 logger = logging.getLogger('antsregister.wrapper')
 for datadir in allseries:
     logger.info(datadir)
     globstr = os.path.join(datadir, 'B13-005_sess*.nii.gz')
     allf = sorted(glob(globstr))
     target = allf[0]
     basedir, _ = os.path.split(target)
     reg.function_logger(basedir)
     allmove = []
     allmoved = [target]
     for movin in allf[1:3]:
         tmpaff = reg.affine_register_cc(target, movin)
         if tmpaff is None:
             continue
         displacement, translate, angles = xfm.params_from_ants(tmpaff)
         allmove.append([translate.tolist() + angles + [displacement]])
         moved = reg.apply_affine(movin, tmpaff)
         allmoved.append(moved)
     ## merge aligned into 4D
     merged_fname = os.path.join(datadir, 'aligned_4d.nii.gz')
     try:
         merged_img = ni.concat_images(allmoved)
         merged_img.to_filename(merged_fname)
     except:
         cmd = 'fslmerge -t %s '%(merged_fname) 
         cmd = cmd + ' '.join([x for x in allmoved])
         os.system(cmd)
     allmove = np.asarray(allmove).squeeze()
     dims = ('x','y','z')
     cols = ['trans_%s'%x for x in dims] + ['rot_%s'%x for x in dims] +\