Mercurial > repos > greg > drmi
changeset 0:94f6b3e28c36 draft
Uploaded
author | greg |
---|---|
date | Fri, 03 Nov 2017 08:52:47 -0400 |
parents | |
children | aeeac311a551 |
files | dmri.py dmri.xml |
diffstat | 2 files changed, 84 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmri.py Fri Nov 03 08:52:47 2017 -0400 @@ -0,0 +1,51 @@ +#!/usr/bin/env python +import argparse +import os +import nibabel +import shutil + +from dipy.data import fetch_sherbrooke_3shell + +parser = argparse.ArgumentParser() +parser.add_argument('--input', dest='input', help='Input dataset') +parser.add_argument('--output', dest='output', help='Output dataset') + +args = parser.parse_args() + +def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): + source_directory = os.path.abspath(source_dir) + destination_directory = os.path.abspath(destination_dir) + if not os.path.isdir(destination_directory): + os.makedirs(destination_directory) + for dir_entry in os.listdir(source_directory): + source_entry = os.path.join(source_directory, dir_entry) + if copy: + shutil.copy(source_entry, destination_directory) + else: + shutil.move(source_entry, destination_directory) + if remove_source_dir: + os.rmdir(source_directory) + +input_dir = 'input_dir' +# Get input data. +fetch_sherbrooke_3shell() +# MNove inputs to working directory. +move_directory_files('/home/greg/.dipy', input_dir) +fdwi = join(input_dir, 'HARDI193.nii.gz') +fbval = join(input_dir, 'HARDI193.bval') +fbvec = join(input_dir, 'HARDI193.bvec') +# Load the dMRI datasets. +img = nibabel.load(fdwi) +data = img.get_data() +# data is a 4D array where the first 3 dimensions are the i, j, +# k voxel coordinates and the last dimension is the number of +# non-weighted (S0s) and diffusion-weighted volumes. +# Visualize the results using matplotlib. +axial_middle = data.shape[2] // 2 +plt.figure('Showing the datasets') +plt.subplot(1, 2, 1).set_axis_off() +plt.imshow(data[:, :, axial_middle, 0].T, cmap='gray', origin='lower') +plt.subplot(1, 2, 2).set_axis_off() +plt.imshow(data[:, :, axial_middle, 10].T, cmap='gray', origin='lower') +plt.show() +plt.savefig(args.output, bbox_inches='tight')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmri.xml Fri Nov 03 08:52:47 2017 -0400 @@ -0,0 +1,33 @@ +<tool id="dmri" name="dMRI" version="0.13.0"> + <description>real-time object detection</description> + <requirements> + <requirement type="package" version="0.13.0">dipy</requirement> + <requirement type="package" version="2.2.0">nibabel</requirement> + <requirement type="package" version="2.1.0">matplotlib</requirement> + </requirements> + <command detect_errors="exit_code"><![CDATA[ +python '$__tool_directory__/drmi.py' +--input '$input' +--output '$output' + ]]></command> + <inputs> + <param name="input" format="nifti1" type="data" label="Image"/> + </inputs> + <outputs> + <data name="output_shape_confidence" format="png" /> + </outputs> + <tests> + <test> + </test> + </tests> + <help> +**What it does** + +----- + +**Options** + + </help> + <citations> + </citations> +</tool>