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
|
|
15 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False):
|
|
16 source_directory = os.path.abspath(source_dir)
|
|
17 destination_directory = os.path.abspath(destination_dir)
|
|
18 if not os.path.isdir(destination_directory):
|
|
19 os.makedirs(destination_directory)
|
|
20 for dir_entry in os.listdir(source_directory):
|
|
21 source_entry = os.path.join(source_directory, dir_entry)
|
|
22 if copy:
|
|
23 shutil.copy(source_entry, destination_directory)
|
|
24 else:
|
|
25 shutil.move(source_entry, destination_directory)
|
|
26 if remove_source_dir:
|
|
27 os.rmdir(source_directory)
|
|
28
|
|
29 input_dir = 'input_dir'
|
|
30 # Get input data.
|
|
31 fetch_sherbrooke_3shell()
|
|
32 # MNove inputs to working directory.
|
|
33 move_directory_files('/home/greg/.dipy', input_dir)
|
|
34 fdwi = join(input_dir, 'HARDI193.nii.gz')
|
|
35 fbval = join(input_dir, 'HARDI193.bval')
|
|
36 fbvec = join(input_dir, 'HARDI193.bvec')
|
|
37 # Load the dMRI datasets.
|
|
38 img = nibabel.load(fdwi)
|
|
39 data = img.get_data()
|
|
40 # data is a 4D array where the first 3 dimensions are the i, j,
|
|
41 # k voxel coordinates and the last dimension is the number of
|
|
42 # non-weighted (S0s) and diffusion-weighted volumes.
|
|
43 # Visualize the results using matplotlib.
|
|
44 axial_middle = data.shape[2] // 2
|
|
45 plt.figure('Showing the datasets')
|
|
46 plt.subplot(1, 2, 1).set_axis_off()
|
|
47 plt.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower')
|
|
48 plt.subplot(1, 2, 2).set_axis_off()
|
|
49 plt.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower')
|
|
50 plt.show()
|
|
51 plt.savefig(args.output, bbox_inches='tight')
|