def dsi2metadata(): import nibabel.nicom.dicomreaders as dr raw_dir = op.join(gconf.get_rawdata()) dsi_dir = op.join(raw_dir, 'DSI') raw_glob = gconf.get_rawglob('diffusion') diffme = gconf.get_diffusion_metadata() try: # extract bvals, bvects, affine from dsi and store them as .txt in NIFTI data, affine, bval, bvect = dr.read_mosaic_dir(dsi_dir, raw_glob) except Exception, e: log.error("There was an exception: %s" % e) return
from dipy.reconst.dti import Tensor from dipy.reconst.dni import DiffusionNabla, EquatorialInversion from dipy.reconst.dsi import DiffusionSpectrum, project_hemisph_bvecs from dipy.tracking.propagation import EuDX from dipy.align.aniso2iso import resample from dipy.viz import fvtk from visualize_dsi import show_blobs #you need to switch to matthew's branch dicom-sorting for nibabel from nibabel.nicom.dicomreaders import read_mosaic_dir if __name__ == '__main__': dirname='/home/eg309/Data/project01_dsi/connectome_0001/tp1/RAWDATA/DSI' data,affine,bvals,bvecs = read_mosaic_dir(dirname,globber='mr*',sort_func='instance number') bvecs[np.isnan(bvecs)]=0 #project identical b-vectors to the other hemisphere bvecs2,pairs=project_hemisph_bvecs(bvals,bvecs) #stop #get voxel size zooms=np.sqrt(np.sum(affine[:3,:3]**2,axis=0)) nzooms=(zooms[0],zooms[0],zooms[0]) #resample datasets print(data.shape) data,affine=resample(data,affine,zooms,nzooms) print(data.shape) #mask a bit the background or load the mask