Mercurial > repos > greg > drmi
comparison dmri.py @ 39:24c3ca0fd7fa draft
Uploaded
| author | greg |
|---|---|
| date | Thu, 30 Nov 2017 11:02:43 -0500 |
| parents | b054adc68274 |
| children | da05d30d0642 |
comparison
equal
deleted
inserted
replaced
| 38:b054adc68274 | 39:24c3ca0fd7fa |
|---|---|
| 4 import shutil | 4 import shutil |
| 5 | 5 |
| 6 from dipy.core.gradients import gradient_table | 6 from dipy.core.gradients import gradient_table |
| 7 from dipy.data import fetch_stanford_hardi, fetch_stanford_t1, read_stanford_labels | 7 from dipy.data import fetch_stanford_hardi, fetch_stanford_t1, read_stanford_labels |
| 8 from dipy.io import read_bvals_bvecs | 8 from dipy.io import read_bvals_bvecs |
| 9 from dipy.io.image import save_nifti | |
| 9 from matplotlib import pyplot | 10 from matplotlib import pyplot |
| 10 | 11 |
| 11 import nibabel | 12 import nibabel |
| 12 | 13 |
| 13 parser = argparse.ArgumentParser() | 14 parser = argparse.ArgumentParser() |
| 66 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') | 67 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') |
| 67 pyplot.subplot(1, 2, 2).set_axis_off() | 68 pyplot.subplot(1, 2, 2).set_axis_off() |
| 68 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') | 69 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') |
| 69 pyplot.savefig('data.png', bbox_inches='tight') | 70 pyplot.savefig('data.png', bbox_inches='tight') |
| 70 shutil.move('data.png', args.output_png) | 71 shutil.move('data.png', args.output_png) |
| 71 # Load the b-values and b-vectors. | 72 |
| 72 bvals, bvecs = read_bvals_bvecs(fbval, fbvec) | 73 if args.drmi_dataset == 'stanford_hardi': |
| 73 gtab = gradient_table(bvals, bvecs) | 74 # Load the b-values and b-vectors. |
| 74 # gtab can be used to tell what part of the data is the S0 | 75 bvals, bvecs = read_bvals_bvecs(fbval, fbvec) |
| 75 # volumes (volumes which correspond to b-values of 0). | 76 gtab = gradient_table(bvals, bvecs) |
| 76 S0s = data[:, :, :, gtab.b0s_mask] | 77 # gtab can be used to tell what part of the data is the S0 |
| 77 # Save this in a new Nifti file. | 78 # volumes (volumes which correspond to b-values of 0). |
| 78 nibabel.save(nibabel.Nifti1Image(S0s, img.affine), 'output.nii') | 79 S0s = data[:, :, :, gtab.b0s_mask] |
| 80 # Save this in a new Nifti file. | |
| 81 nibabel.save(nibabel.Nifti1Image(S0s, img.affine), 'output.nii') | |
| 82 else: | |
| 83 save_nifti('output.nii', data, img.affine) | |
| 84 | |
| 79 shutil.move('output.nii', args.output_nifti1) | 85 shutil.move('output.nii', args.output_nifti1) |
| 80 # Move the entire contents of input_dir to output_nifti1_extra_files. | 86 # Move the entire contents of input_dir to output_nifti1_extra_files. |
| 81 move_directory_files(input_dir, args.output_nifti1_extra_files) | 87 move_directory_files(input_dir, args.output_nifti1_extra_files) |
| 88 |
