Mercurial > repos > greg > fast_fiber_tracking
comparison fast_fiber_tracking.py @ 3:63aa79b5ebd6 draft
Uploaded
author | greg |
---|---|
date | Thu, 30 Nov 2017 09:10:46 -0500 |
parents | 4e3d4331fa58 |
children | 66b5ff1ff984 |
comparison
equal
deleted
inserted
replaced
2:a695440febc0 | 3:63aa79b5ebd6 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 import argparse | 2 import argparse |
3 import os | |
3 import shutil | 4 import shutil |
4 | 5 |
5 from dipy.data import fetch_sherbrooke_3shell | 6 from dipy.data import fetch_sherbrooke_3shell |
6 from dipy.data import fetch_stanford_hardi | 7 from dipy.data import fetch_stanford_hardi |
7 from dipy.data import get_sphere | 8 from dipy.data import get_sphere |
18 from dipy.viz import actor, window | 19 from dipy.viz import actor, window |
19 | 20 |
20 import numpy as np | 21 import numpy as np |
21 | 22 |
22 parser = argparse.ArgumentParser() | 23 parser = argparse.ArgumentParser() |
23 parser.add_argument('--drmi_dataset', dest='drmi_dataset', help='Input dataset') | 24 parser.add_argument('--input', dest='input', help='Input dataset') |
24 parser.add_argument('--output_csd_direction_field', dest='output_csd_direction_field', help='Output csd direction field dataset') | 25 parser.add_argument('--output_csd_direction_field', dest='output_csd_direction_field', help='Output csd direction field dataset') |
25 parser.add_argument('--output_det_streamlines', dest='output_det_streamlines', help='Output det streamlines dataset') | 26 parser.add_argument('--output_det_streamlines', dest='output_det_streamlines', help='Output det streamlines dataset') |
26 parser.add_argument('--output_fa_map', dest='output_fa_map', help='Output fa map dataset') | 27 parser.add_argument('--output_fa_map', dest='output_fa_map', help='Output fa map dataset') |
28 parser.add_argument('--output_fa_map_files_path', dest='output_fa_map_files_path', help='Output fa map extra files path') | |
27 | 29 |
28 args = parser.parse_args() | 30 args = parser.parse_args() |
31 | |
32 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): | |
33 source_directory = os.path.abspath(source_dir) | |
34 destination_directory = os.path.abspath(destination_dir) | |
35 if not os.path.isdir(destination_directory): | |
36 os.makedirs(destination_directory) | |
37 for dir_entry in os.listdir(source_directory): | |
38 source_entry = os.path.join(source_directory, dir_entry) | |
39 if copy: | |
40 shutil.copy(source_entry, destination_directory) | |
41 else: | |
42 shutil.move(source_entry, destination_directory) | |
43 if remove_source_dir: | |
44 os.rmdir(source_directory) | |
29 | 45 |
30 interactive = False | 46 interactive = False |
31 | 47 |
32 # Get input data. | 48 # Get input data. |
33 input_dir = args.drmi_dataset | 49 # TODO: do not hard-code 'stanford_hardi' |
34 if input_dir == 'sherbrooke_3shell': | 50 input_dir = 'stanford_hardi' |
35 fetch_sherbrooke_3shell() | 51 os.mkdir(input_dir) |
36 img, gtab = read_sherbrooke_3shell() | 52 for f in os.listdir(args.input_extra_files_path): |
37 elif input_dir == 'stanford_hardi': | 53 shutil.copy(os.path.join(args.input_extra_files_path, f), input_dir) |
38 fetch_stanford_hardi() | 54 img, gtab = read_stanford_hardi() |
39 img, gtab = read_stanford_hardi() | |
40 | 55 |
41 data = img.get_data() | 56 data = img.get_data() |
42 maskdata, mask = median_otsu(data, 3, 1, False, vol_idx=range(10, 50), dilate=2) | 57 maskdata, mask = median_otsu(data, 3, 1, False, vol_idx=range(10, 50), dilate=2) |
43 | 58 |
44 response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7) | 59 response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7) |
66 window.record(ren, out_path='det_streamlines.png', size=(900, 900)) | 81 window.record(ren, out_path='det_streamlines.png', size=(900, 900)) |
67 shutil.move('det_streamlines.png', args.output_det_streamlines) | 82 shutil.move('det_streamlines.png', args.output_det_streamlines) |
68 | 83 |
69 save_nifti('fa_map.nii', fa, img.affine) | 84 save_nifti('fa_map.nii', fa, img.affine) |
70 shutil.move('fa_map.nii', args.output_fa_map) | 85 shutil.move('fa_map.nii', args.output_fa_map) |
86 move_directory_files(input_dir, args.output_fa_map_files_path, copy=True) |