Mercurial > repos > greg > drmi
comparison dmri.py @ 21:53671fcb9507 draft
Uploaded
| author | greg |
|---|---|
| date | Sun, 05 Nov 2017 07:33:21 -0500 |
| parents | 3938c3299e7b |
| children | 814082359f36 |
comparison
equal
deleted
inserted
replaced
| 20:fcdb8f5e9c8f | 21:53671fcb9507 |
|---|---|
| 8 from dipy.data import fetch_sherbrooke_3shell | 8 from dipy.data import fetch_sherbrooke_3shell |
| 9 from dipy.io import read_bvals_bvecs | 9 from dipy.io import read_bvals_bvecs |
| 10 from matplotlib import pyplot | 10 from matplotlib import pyplot |
| 11 | 11 |
| 12 parser = argparse.ArgumentParser() | 12 parser = argparse.ArgumentParser() |
| 13 parser.add_argument('--input', dest='input', help='Input dataset') | 13 parser.add_argument('--drmi_dataset', dest='drmi_dataset', help='Input dataset') |
| 14 parser.add_argument('--output_nifti1', dest='output_nifti1', help='Output Nifti1 dataset') | 14 parser.add_argument('--output_nifti1', dest='output_nifti1', help='Output Nifti1 dataset') |
| 15 parser.add_argument('--output_png', dest='output_png', help='Output dataset') | 15 parser.add_argument('--output_png', dest='output_png', help='Output dataset') |
| 16 | 16 |
| 17 args = parser.parse_args() | 17 args = parser.parse_args() |
| 18 | 18 |
| 19 input_dir = 'sherbrooke_3shell' | |
| 20 # Get input data. | 19 # Get input data. |
| 21 fetch_sherbrooke_3shell() | 20 input_dir = args.drmi_dataset |
| 21 if args.drmi_dataset == 'sherbrooke_3shell': | |
| 22 fetch_sherbrooke_3shell() | |
| 23 elif args.drmi_dataset == 'stanford_hardi': | |
| 24 fetch_stanford_hardi() | |
| 22 fdwi = os.path.join(input_dir, 'HARDI193.nii.gz') | 25 fdwi = os.path.join(input_dir, 'HARDI193.nii.gz') |
| 23 fbval = os.path.join(input_dir, 'HARDI193.bval') | 26 fbval = os.path.join(input_dir, 'HARDI193.bval') |
| 24 fbvec = os.path.join(input_dir, 'HARDI193.bvec') | 27 fbvec = os.path.join(input_dir, 'HARDI193.bvec') |
| 25 # Load the dMRI datasets. | 28 # Load the dMRI datasets. |
| 26 img = nibabel.load(fdwi) | 29 img = nibabel.load(fdwi) |
| 28 # data is a 4D array where the first 3 dimensions are the i, j, | 31 # data is a 4D array where the first 3 dimensions are the i, j, |
| 29 # k voxel coordinates and the last dimension is the number of | 32 # k voxel coordinates and the last dimension is the number of |
| 30 # non-weighted (S0s) and diffusion-weighted volumes. | 33 # non-weighted (S0s) and diffusion-weighted volumes. |
| 31 # Visualize the results using matplotlib. | 34 # Visualize the results using matplotlib. |
| 32 axial_middle = data.shape[2] // 2 | 35 axial_middle = data.shape[2] // 2 |
| 33 pyplot.figure('Showing the datasets') | |
| 34 pyplot.subplot(1, 2, 1).set_axis_off() | 36 pyplot.subplot(1, 2, 1).set_axis_off() |
| 35 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') | 37 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') |
| 36 pyplot.subplot(1, 2, 2).set_axis_off() | 38 pyplot.subplot(1, 2, 2).set_axis_off() |
| 37 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') | 39 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') |
| 38 pyplot.savefig('data.png', bbox_inches='tight') | 40 pyplot.savefig('data.png', bbox_inches='tight') |
