0
|
1 #!/usr/bin/env python
|
|
2 import argparse
|
|
3 import os
|
|
4 import nibabel
|
|
5 import shutil
|
|
6
|
|
7 from dipy.data import fetch_sherbrooke_3shell
|
|
8
|
|
9 parser = argparse.ArgumentParser()
|
|
10 parser.add_argument('--input', dest='input', help='Input dataset')
|
|
11 parser.add_argument('--output', dest='output', help='Output dataset')
|
|
12
|
|
13 args = parser.parse_args()
|
|
14
|
10
|
15 input_dir = 'sherbrooke_3shell'
|
9
|
16 # Get input data.
|
|
17 fetch_sherbrooke_3shell()
|
|
18 fdwi = os.path.join(input_dir, 'HARDI193.nii.gz')
|
|
19 fbval = os.path.join(input_dir, 'HARDI193.bval')
|
|
20 fbvec = os.path.join(input_dir, 'HARDI193.bvec')
|
0
|
21 # Load the dMRI datasets.
|
|
22 img = nibabel.load(fdwi)
|
|
23 data = img.get_data()
|
|
24 # data is a 4D array where the first 3 dimensions are the i, j,
|
|
25 # k voxel coordinates and the last dimension is the number of
|
|
26 # non-weighted (S0s) and diffusion-weighted volumes.
|
|
27 # Visualize the results using matplotlib.
|
|
28 axial_middle = data.shape[2] // 2
|
|
29 plt.figure('Showing the datasets')
|
|
30 plt.subplot(1, 2, 1).set_axis_off()
|
|
31 plt.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower')
|
|
32 plt.subplot(1, 2, 2).set_axis_off()
|
|
33 plt.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower')
|
|
34 plt.show()
|
|
35 plt.savefig(args.output, bbox_inches='tight')
|