Last active
October 13, 2015 00:36
-
-
Save chrisgorgo/d6cd4dcbf06542a9af9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import dicom, nibabel.nicom.csareader | |
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