Skip to content

Instantly share code, notes, and snippets.

@chrisgorgo
Created November 28, 2015 18:11
Show Gist options
  • Save chrisgorgo/64cd06e50c6dacdca39b to your computer and use it in GitHub Desktop.
Save chrisgorgo/64cd06e50c6dacdca39b to your computer and use it in GitHub Desktop.
def save_diffusion_vec(dcm_files, out_bvecs, out_bvals):
bvals = []
bvecs = []
for dcm_file in dcm_files:
dcm_dat = dicom.read_file(dcm_file)
csa = nibabel.nicom.csareader.get_csa_header(dcm_dat)
bval = nibabel.nicom.csareader.get_b_value(csa)
bvec = nibabel.nicom.csareader.get_g_vector(csa)
bvals.append(bval)
bvecs.append(bvec)
bvals = np.array(bvals)
bvecs = np.array(bvecs)
np.savetxt(out_bvecs, bvecs.T, delimiter=" ", fmt='%.4g')
np.savetxt(out_bvals, bvals.reshape(-1,1).T, delimiter=" ", fmt='%.4g')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment