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