Mercurial > repos > greg > drmi
comparison dmri.py @ 41:da05d30d0642 draft default tip
Uploaded
| author | greg |
|---|---|
| date | Thu, 30 Nov 2017 11:09:07 -0500 |
| parents | 24c3ca0fd7fa |
| children |
comparison
equal
deleted
inserted
replaced
| 40:1e2dad266344 | 41:da05d30d0642 |
|---|---|
| 14 parser = argparse.ArgumentParser() | 14 parser = argparse.ArgumentParser() |
| 15 parser.add_argument('--drmi_dataset', dest='drmi_dataset', help='Input dataset') | 15 parser.add_argument('--drmi_dataset', dest='drmi_dataset', help='Input dataset') |
| 16 parser.add_argument('--drmi_dataset_type', dest='drmi_dataset_type', help='Input dataset type') | 16 parser.add_argument('--drmi_dataset_type', dest='drmi_dataset_type', help='Input dataset type') |
| 17 parser.add_argument('--output_nifti1', dest='output_nifti1', help='Output Nifti1 dataset') | 17 parser.add_argument('--output_nifti1', dest='output_nifti1', help='Output Nifti1 dataset') |
| 18 parser.add_argument('--output_nifti1_extra_files', dest='output_nifti1_extra_files', help='Output Nifti1 extra files') | 18 parser.add_argument('--output_nifti1_extra_files', dest='output_nifti1_extra_files', help='Output Nifti1 extra files') |
| 19 parser.add_argument('--output_png', dest='output_png', help='Output dataset') | 19 parser.add_argument('--output_png', dest='output_png', default=None, help='Output dataset') |
| 20 | 20 |
| 21 args = parser.parse_args() | 21 args = parser.parse_args() |
| 22 | 22 |
| 23 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): | 23 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): |
| 24 source_directory = os.path.abspath(source_dir) | 24 source_directory = os.path.abspath(source_dir) |
| 58 | 58 |
| 59 data = img.get_data() | 59 data = img.get_data() |
| 60 # data is a 4D array where the first 3 dimensions are the i, j, | 60 # data is a 4D array where the first 3 dimensions are the i, j, |
| 61 # k voxel coordinates and the last dimension is the number of | 61 # k voxel coordinates and the last dimension is the number of |
| 62 # non-weighted (S0s) and diffusion-weighted volumes. | 62 # non-weighted (S0s) and diffusion-weighted volumes. |
| 63 # Visualize the results using matplotlib. | 63 |
| 64 axial_middle = data.shape[2] // 2 | |
| 65 pyplot.subplot(1, 2, 1).set_axis_off() | |
| 66 if args.drmi_dataset == 'stanford_hardi': | 64 if args.drmi_dataset == 'stanford_hardi': |
| 65 # Visualize the results using matplotlib. | |
| 66 axial_middle = data.shape[2] // 2 | |
| 67 pyplot.subplot(1, 2, 1).set_axis_off() | |
| 67 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') | 68 pyplot.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') |
| 68 pyplot.subplot(1, 2, 2).set_axis_off() | 69 pyplot.subplot(1, 2, 2).set_axis_off() |
| 69 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') | 70 pyplot.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') |
| 70 pyplot.savefig('data.png', bbox_inches='tight') | 71 pyplot.savefig('data.png', bbox_inches='tight') |
| 71 shutil.move('data.png', args.output_png) | 72 shutil.move('data.png', args.output_png) |
| 72 | |
| 73 if args.drmi_dataset == 'stanford_hardi': | |
| 74 # Load the b-values and b-vectors. | 73 # Load the b-values and b-vectors. |
| 75 bvals, bvecs = read_bvals_bvecs(fbval, fbvec) | 74 bvals, bvecs = read_bvals_bvecs(fbval, fbvec) |
| 76 gtab = gradient_table(bvals, bvecs) | 75 gtab = gradient_table(bvals, bvecs) |
| 77 # gtab can be used to tell what part of the data is the S0 | 76 # gtab can be used to tell what part of the data is the S0 |
| 78 # volumes (volumes which correspond to b-values of 0). | 77 # volumes (volumes which correspond to b-values of 0). |
| 83 save_nifti('output.nii', data, img.affine) | 82 save_nifti('output.nii', data, img.affine) |
| 84 | 83 |
| 85 shutil.move('output.nii', args.output_nifti1) | 84 shutil.move('output.nii', args.output_nifti1) |
| 86 # Move the entire contents of input_dir to output_nifti1_extra_files. | 85 # Move the entire contents of input_dir to output_nifti1_extra_files. |
| 87 move_directory_files(input_dir, args.output_nifti1_extra_files) | 86 move_directory_files(input_dir, args.output_nifti1_extra_files) |
| 88 |
