Created
November 28, 2015 18:11
-
-
Save chrisgorgo/64cd06e50c6dacdca39b 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
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