Last active
August 29, 2015 13:57
-
-
Save njvack/9674025 to your computer and use it in GitHub Desktop.
A wrapper to allow Freesurfer's mri_convert to work on a tarball of dicoms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
in_file="$1" | |
out_file="$2" | |
out_base=$(dirname "${out_file}") | |
tmp_dir=$(mktemp -d -p "${out_base}") | |
if [ $? -ne 0 ]; then | |
echo "Can't make a temporary directory in ${out_base}" >&2 | |
exit 1 | |
fi | |
echo -n "Untarring ${in_file} to ${tmp_dir}" | |
tar -C "${tmp_dir}" -xf "${in_file}" --checkpoint=.100 | |
if [ $? -ne 0 ]; then | |
echo | |
echo "Error untarring ${in_file}" >&2 | |
rmdir "${tmp_dir}" | |
exit 2 | |
fi | |
echo | |
echo "Converting..." | |
# This will find you the first file... | |
first_file=$(find "${tmp_dir}" -type f | sed 1q) | |
mri_convert "${first_file}" "${out_file}" | |
'rm' -r "${tmp_dir}" |
I tried dcmstack; it was too slow for my purposes. mri_convert handles an 8400-slice EPI series in less than a minute; I gave up after waiting an hour for dcmstack to do its tricks.
It's a pity, because I really would like to annotate the niftis with the dicom headers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@njvack: would tarfile + pydicom + dcmstack let you do this with untarring?